+

Search Tips   |   Advanced Search

SELECT clause

The SELECT clause consists of either a single identification variable defined in the FROM clause, or a single valued path expression that evaluates to an object reference or container managed persistence (CMP) value. We can use the DISTINCT keyword to eliminate duplicate references.

For finder and select queries, the syntax of the SELECT clause is illustrated in the following example:

For a query that defines a finder method, the query must return an object type consistent with the home that is associated with the finder method. For example, a finder method for a department home can not return employee objects.


Example: SELECT clause

Find all employees that earn more than John:

Find all departments that have one or more employees who earn less than 20000:

A select method query can have a path expression that evaluates to an arbitrary value:

The previous query returns a collection of name values for those departments having employees earning less than 20000.

A select method query can return an aggregate value:


Example: Valid dynamic queries

For dynamic queries the syntax is as follows:

SELECT { ALL | DISTINCT }  [ selection , ]*  selection
selection  ::= { expression   |  scalar-subselect [[AS] id ] }

A scalar-subselect is a subselect that returns a single value.

The following are examples of dynamic queries:


Related concepts

  • EJB query language


    Related tasks

  • Use EJB query