Chapter 8 Home | Prev: 8.6 Filtering with WHERE | Next: 8.6.2 Filtering with Aliases
Wild cards allow queries to return results regardless of exact matches. This is extremely powerful in searches and filtering operations. Wild cards will be interpreted as exact matches if used with any comparator other than LIKE
.
Key Character | Description |
% | The percent wildcard specifies that any characters can appear in multiple positions represented by the wildcard. |
_ | The underscore wildcard specifies a single position in which any character can occur. |
LIKE Operator | Description |
---|---|
WHERE LOWER(CustomerName) LIKE 'a%' | Finds any values that starts with "a" |
WHERE LOWER(CustomerName) LIKE '%a' | Finds any values that ends with "a" |
WHERE LOWER(CustomerName) LIKE '%or%' | Finds any values that have "or" in any position |
WHERE LOWER(CustomerName) LIKE '_r%' | Finds any values that have "r" in the second position |
WHERE LOWER(CustomerName) LIKE 'a_%_%' | Finds any values that starts with "a" and are at least 3 characters in length |
WHERE LOWER(ContactName) LIKE 'a%o' | Finds any values that starts with "a" and ends with "o" |
WHERE LOWER(productName) LIKE '_at' | Would find any 3 letter name ending in at (hat, cat, bat, pat, sat, mat, etc....) |
WHERE LOWER(productName) = '_at' | would not likely find any results, as the product name would have to be exactly '_at' the wildcard is only recognized with the LIKE comparison operator. |
SELECT firstname, lastname FROM customers WHERE Upper(firstname) LIKE 'B%';