mode helix
NOW LIVEEmpower your end users with Explorations in Mode.Try it now


Starting here? This lesson is part of a full-length tutorial in using SQL for Data Analysis. Check out the beginning.

In this lesson we'll cover:

The SQL LIKE operator

LIKE is a logical operator in SQL that allows you to match on similar values rather than exact ones.

In this example, the results from the Billboard Music Charts dataset will include rows for which "group" starts with "Snoop" and is followed by any number and selection of characters.

Run the code to see which results are returned.

  FROM tutorial.billboard_top_100_year_end
 WHERE "group" LIKE 'Snoop%'

Note: "group" appears in quotations above because GROUP is actually the name of a function in SQL. The double quotes (as opposed to single: ') are a way of indicating that you are referring to the column name "group", not the SQL function. In general, putting double quotes around a word or phrase will indicate that you are referring to that column name.

Wildcards and ILIKE

The % used above represents any character or set of characters. In this case, % is referred to as a "wildcard." In the type of SQL that Mode uses, LIKE is case-sensitive, meaning that the above query will only capture matches that start with a capital "S" and lower-case "noop." To ignore case when you're matching values, you can use the ILIKE command:

  FROM tutorial.billboard_top_100_year_end
 WHERE "group" ILIKE 'snoop%'

You can also use _ (a single underscore) to substitute for an individual character:

  FROM tutorial.billboard_top_100_year_end
 WHERE artist ILIKE 'dr_ke'

Sharpen your SQL skills

Practice Problem

Write a query that returns all rows for which Ludacris was a member of the group.

Try it out See the answer

Practice Problem

Write a query that returns all rows for which the first artist listed in the group has a name that begins with "DJ".

Try it out See the answer

Next Lesson


decorative particle

Get our weekly data newsletter

Work-related distractions for every data enthusiast.