SQL IN
Test whether a value equals any value in a list.
Syntax
WHERE col IN (value1, value2, …) WHERE col IN (SELECT …)
Shorter than many ORs. The list can be a subquery.
Example
Query (on the shop database used in the SQL course)
SELECT name, country FROM customers WHERE country IN ('Nepal', 'Canada');
Result
| name | country |
|---|---|
| Ava Wilson | Nepal |
| Hiroshi Tanaka | Nepal |
| Jack Murphy | Nepal |
| Leo Rossi | Nepal |
4 rows
Good to know. NOT IN returns no rows if the list contains a NULL: prefer NOT EXISTS with subqueries.
Related
Learn it step by step in the free lesson WHERE: Filtering Rows, with exercises that check your queries.