NOT IN Operator in SQL

Level 252 keystrokes

NOT IN excludes rows where the value matches any value in the list.

SQL code

1SELECT
-- Returns the name of each remaining product
2 name
3FROM
4 products
5WHERE
-- NOT IN excludes the products with id 1, 3 or 5
-- Beware: if the list contained NULL, no row would match
6 id NOT IN (1, 3, 5);

Output

+--------+
| name   |
+--------+
| Gadget |
| Widget |
+--------+
2 rows in set
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this SQL code and how often they appear.

  • ,× 2
  • ;× 1
  • (× 1
  • )× 1

More SQL examples at level 2

← SQL typing practice