Starting here? This lesson is part of a full-length tutorial in using SQL for Data Analysis. Check out the beginning.
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:
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:
WHERE artist IN ('Taylor Swift', 'Usher', 'Ludacris')
Sharpen your SQL skills
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.