21

The [NOT] IN() Predicate

The IN() predicate is one of the “abbreviations” that is allowed in SQL. It can be expanded into the usual AND, OR, and NOT logical operators, but it is easier to see the intent of the programmer with this syntax. New SQL programmers stick to the more familiar “nonabbreviated” logic for two reasons: (1) it looks like their procedural language and (2) they think the optimizer will do better with nonabbreviated logic. This is not true at all.

The IN() syntax is very natural and was borrowed and generalized from the Pascal language. It takes a value on the left side and sees if it is in a list of comparable values on the right side. Standard SQL allows value expressions in the list or for you to use a query to construct ...

Get Joe Celko's SQL for Smarties, 4th Edition 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.