Menu
Coddy logo textTech

The IN keyword

Part of the Fundamentals section of Coddy's SQL journey — lesson 18 of 72.

When we need to find rows where a column matches any one of several possible values, we can write it using multiple OR conditions. For example the following query is very long:

SELECT *
FROM table1
WHERE col1 = 'a' OR col1 = 'b' OR col1 = 'c' OR col1 = 'd' OR ...

We can simplify it by using the IN keyword like this:

SELECT *
FROM table1
WHERE col1 IN ('a', 'b', 'c', 'd', 'e', 'f')

This shorter version does exactly the same thing: it returns rows where col1 equals any of the values listed in the parentheses.

challenge icon

Challenge

Easy

Available tables and columns:

  • <strong>countries</strong>: <strong>location_x</strong>, <strong>location_y</strong>, <strong>country</strong>

Return all the records from the following countries:

Oman, Nicaragua, Bhutan, Senegal, Belarus

Cheat sheet

Use IN to check if a column matches any value from a list:

SELECT *
FROM table1
WHERE col1 IN ('a', 'b', 'c', 'd', 'e', 'f')

This is equivalent to multiple OR conditions but much shorter.

Try it yourself

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals