

SIMILAR is the more advanced way to match a string to a pattern, using a standard pattern format called regular expressions (regexp). You can play around with patterns yourself by switching the LIKE statements out here SIMILAR TO 'Little Richard' LIKE '%Richard' true 'Little Richard' LIKE '_Richard' true 'Little Richard' LIKE '_Richard' false 'Little Richard' LIKE '%richard' false 'Little Richard' ILIKE '%richARD' true 'Little Richard' LIKE '_ittle %' true

Here are a few more examples of what patterns will and won’t match. Note that in the above query if we switched ILIKE to LIKE we wouldn’t match any Green Day tracks because Day is capitalized. So if we wanted to find all composers that had the word “day” in it regardless of case, we could use: If you want your pattern to not care about whether characters are upper or lower case you can use ILIKE. Test your skill: can you create a query to return all of the artists with ‘Black’ in their name? ILIKE So with this pattern as our condition, on running the following query the database will scan for matches in each row and return those that are true. To make a pattern that will match ‘Green Day’ inside of any string we put % symbols on either side, meaning any number of characters can be before or after Green Day. Besides regular characters, the two wildcard symbols LIKE can use are Symbol A pattern is a string that can use some special symbols that represent wildcard characters. Like is the easy/lightweight way to match a string to a pattern. They take a bit more explanation than the simple comparators above. To condition match part of a string, or identify strings following a pattern we can use either of these string pattern matching operators.

If we want to find all the tracks that were composed by Green Day (either alone, or in conjunction with other artists) we need to be able to match rows where the composer isn’t equal to ‘Green Day’ but contain ‘Green Day’ somewhere in them. But that condition only does an exact match and therefore only matches songs that were exclusively written by Green Day. When you want to match an exact string (like composer = 'Green Day') you can simply use the equal ( =) operator. Here’s a query to get started with: String operators and Patterns Take a few moments to get familiar with these operators by filtering out some tracks data. Here’s the table describing the most commonly used operators: Operator They are fairly self-explanatory and just need some practice to get down. So far we’ve only made conditions using the equal ( =) or greater than ( >) operators.
