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 an object reference or container managed persistence (CMP) value. You can use the DISTINCT keyword to eliminate duplicate references.
SELECT [ ALL | DISTINCT ] { single-valued-path-expression | aggregation expression | OBJECT ( identification-variable ) }
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.
SELECT OBJECT(e) FROM EmpBean ej, EmpBean e WHERE ej.name = 'John' and e.salary > ej.salary
SELECT DISTINCT e.dept FROM EmpBean e where e.salary < 20000
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.
SELECT avg(e.salary) FROM EmpBean e
SELECT { ALL | DISTINCT } [ selection , ]* selection selection ::= { expression | scalar-subselect [[AS] id ] }
A scalar-subselect is a subselect that returns a single value.
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