What if we are trying to match on a specific text length?


#1

Question

In the context of this code challenge, what if we are trying to match on a specific text length?

Answer

If you are searching for a match on some specific text length, then instead of utilizing the % wildcard, which will match 0 or more characters, consider utilizing the _ wildcard for single character matches.

For example, say that you only remember that some restaurant name had 6 or 7 letters, and started with the letters "Del". What you can do is utilize the _ wildcard to match for a specific number of characters, up to a length of 6 or 7.

SELECT name
FROM restaurants
WHERE name LIKE 'Del___' /* matches "Del" followed by any 3 characters */
OR name LIKE 'Del____';  /* matches "Del" followed by any 4 characters */