List Filtering with IN

Use IN to determine whether a given value matches any value in a specified list. The IN condition’s important characteristics are:

  • IN works with character strings, numbers, and datetimes.

  • The IN list is a parenthesized listing of one or more comma-separated values. The list items needn’t be in any particular order.

  • IN is a convenient, shorthand clause. You can replicate its behavior by using OR:

    WHERE test_column IN
          (value1, value2, value3)
    

    is equivalent to:

    WHERE (test_column = value1)
       OR (test_column = value2)
       OR (test_column = value3)
    
  • String comparisons may be case-insensitive or case-sensitive, depending on your DBMS; see the DBMS Tip in “Filtering Rows with WHERE” earlier in this chapter.

  • You can negate an IN condition ...

Get SQL: Visual QuickStart Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.