NOT IN ()

Imagine you want to exclude several rows of data, let’s say you would like to exclude data from California, Texas, Florida, and New York on the right original dataset on the top. See below for a quick way to exclude multiple items within a column:

SELECT *

FROM database_table

WHERE State NOT IN ( ‘California‘, ‘Texas‘, ‘Florida‘, ‘New York‘ )

  • Rather than specifying “State != ‘California‘ AND State != ‘Texas‘ AND State != ‘Florida‘ AND State != ‘New York‘ ” the above SQL syntax provides for a simpler way to exclude multiple items, and using the NOT IN operator is essentially the same as ensuring State is not in a list of symbols—in more complex SQL queries, we’ll use this NOT IN () syntax as well.