O'Reilly logo

Joe Celko's SQL for Smarties, 4th Edition by Joe Celko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

22

EXISTS() Predicate

The EXISTS predicate is very natural. It is a test for a nonempty set (read: table). 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> ::= [NOT] 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 an asterisk ()). 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. Things are better today.

Some early SQL ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required