PreviousSQL Engine Reference (8.7 revision 1) Next

EXISTS

Show this topic in Library frames

Remarks

Use the EXISTS keyword to test whether rows exist in the result of the subquery. For every row the outer query evaluates, Pervasive.SQL V8 tests for the existence of a related row from the subquery. Pervasive.SQL V8 includes in the statement's result table each row from the outer query that corresponds to a related row from the subquery.

In most cases, a subquery with EXISTS can be rewritten to use IN. The SRDE can process the query more efficiently if the query uses IN.

Examples

The following statement returns a list containing only persons who have a 4.0 grade point average:

SELECT * FROM Person p WHERE EXISTS 
(SELECT * FROM Enrolls e WHERE e.Student_ID = p.id 
AND Grade = 4.0) 

This statement can be rewritten to use IN:

SELECT * FROM Person p WHERE p.id IN 
(SELECT e.Student_ID FROM Enrolls WHERE Grade = 4.0) 

See Also

SELECT


Chapter contents
Publication contents

Prev topic: END
Next topic: FETCH