The EXISTS predicate can be used to check for the existence of specific rows. The query_expression returns rows rather than values. The predicate evaluates to true if the number of rows returned by the query_expression is nonzero.

Syntax

This is the syntax for an EXISTS predicate:

EXISTS (query_expression)

Example

In this example, the predicate returns the item names of all items which contain sub-items:

SELECT itemname FROM pub.mtitem 
  WHERE EXISTS(SELECT subitem FROM pub.mtitem);