WebSphere Application Server Network Deployment, Version 6.0.x     Operating Systems: AIX, HP-UX, Linux, Solaris, Windows

SELECT clause

For finder and select queries, the syntax of the SELECT clause is illustrated in the following example:
SELECT  [  ALL | DISTINCT  ]  
	{ single-valued-path-expression  |  aggregation expression  |  OBJECT ( identification-variable )  }

The SELECT clause consists of either a single identification variable that is defined in the FROM clause, or a single valued path expression that evaluates to a object reference or CMP value. You can use the DISTINCT keyword to eliminate duplicate references.

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:
SELECT OBJECT(e) FROM EmpBean ej, EmpBean e 
WHERE  ej.name = 'John'  and e.salary > ej.salary
Find all departments that have one or more employees who earn less than 20000:
SELECT DISTINCT  e.dept  FROM EmpBean e where e.salary < 20000
A select method query can have a path expression that evaluates to an arbitrary value:
SELECT  e.dept.name  FROM EmpBean e where e.salary < 2000

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:
SELECT  avg(e.salary)  FROM EmpBean e

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:
SELECT e.name, e.salary+e.bonus as total_pay from EmpBean e
SELECT  SUM( e.salary+e.bonus) from EmpBean e where e.dept.deptno = ?1



Related concepts
EJB query language

Related tasks
Using EJB query

Concept topic    

Terms of Use | Feedback

Last updated: Dec 11, 2005 4:07:15 PM CST
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=/com.ibm.websphere.nd.doc/info/ae/ae/cque_select.html

© Copyright IBM Corporation 2004, 2005. All Rights Reserved.
This information center is powered by Eclipse technology. (http://www.eclipse.org)