602SQL Documentation Index  

EXISTS Predicate

EXISTS_predicate ::= EXISTS ( query_expression )

The EXISTS predicate determines whether there is at least one record in the query phrase (subquery) result.

Example:

Select the companies that do not have an invoice.

SELECT name
FROM Companies F
WHERE NOT EXISTS (SELECT * FROM Invoices A
                  WHERE A.name=F.name)

Usage outside a SELECT statement.

IF EXISTS (SELECT admin_enabled FROM System 
           WHERE (admin_name=usr)AND(admin_password=pwd)AND(admin_enabled IS TRUE)) 
  THEN ...