Chapter 15. EXISTS() Predicate

THE EXISTS PREDICATE IS very natural. It is a test for a nonempty set. If there are any rows in its subquery, it is TRUE; otherwise, it is FALSE. This predicate does not give an UNKNOWN result. The syntax is:

<exists predicate> ::= EXISTS <table subquery>

It is worth mentioning that a <table subquery> is always inside parentheses to avoid problems in the grammar during parsing.

In SQL-89, the rules stated that the subquery had to have a SELECT clause with one column or a *. If the SELECT * option was used, the database engine would (in theory) pick one column and use it. This fiction was needed because SQL-89 defined subqueries as having only one column.

Some early SQL implementations would work better with EXISTS(SELECT ...

Get Joe Celko's SQL for Smarties, 3rd 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.