Network Deployment (Distributed operating systems), v8.0 > Develop and deploying applications > Develop Dynamic and EJB query > Develop applications that use EJB query > EJB query language > WHERE clause


EXISTS predicate

The exists predicate tests for the presence or absence of a condition specified by a subselect.

Use the syntax:

EXISTS ( subselect )
EXISTS collection-valued-path-expression

The result of EXISTS is true if the subselect returns at least one value or the path expression evaluates to a nonempty collection, otherwise the result is false.

To negate an EXISTS predicate, precede it with the logical operator NOT.


Example: EXISTS predicate

Return departments that have at least one employee earning more than 1000000:

SELECT  OBJECT(d) FROM  DeptBean d
WHERE EXISTS ( SELECT  1  FROM IN (d.emps) e WHERE  e.salary > 1000000 )

Return departments that have no employees:

SELECT OBJECT(d) FROM DeptBean d
WHERE NOT EXISTS  ( SELECT 1 FROM IN (d.emps) e)

The above query can also be written as follows:

SELECT OBJECT(d) FROM DeptBean d WHERE NOT EXISTS d.emps

EJB query language
WHERE clause
Use EJB query

+

Search Tips   |   Advanced Search