ThoughtSpot acquires Mode to define the next generation of collaborative BI >>Learn More


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 IN operator

IN is a logical operator in SQL that allows you to specify a list of values that you'd like to include in the results. For example, the following query of data from the Billboard Music Charts will return results for which the year_rank column is equal to one of the values in the list:

  FROM tutorial.billboard_top_100_year_end
 WHERE year_rank IN (1, 2, 3)

As with comparison operators, you can use non-numerical values, but they need to go inside single quotes. Regardless of the data type, the values in the list must be separated by commas. Here's another example:

  FROM tutorial.billboard_top_100_year_end
 WHERE artist IN ('Taylor Swift', 'Usher', 'Ludacris')

Sharpen your SQL skills

Practice Problem

Write a query that shows all of the entries for Elvis and M.C. Hammer.

Hint: M.C. Hammer is actually on the list under multiple names, so you may need to first write a query to figure out exactly how M.C. Hammer is listed. You're likely to face similar problems that require some exploration in many real-life scenarios.

Try it out See the answer

Next Lesson


Get more from your data

Your team can be up and running in 30 minutes or less.