12.11.2014 Views

web server - Borland Technical Publications

web server - Borland Technical Publications

web server - Borland Technical Publications

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Support for ORDER BY<br />

Support for ORDER BY<br />

The EJB 2.0 Specification supports three SQL clauses in EJB-QL: SELECT, FROM, and<br />

WHERE.<br />

The <strong>Borland</strong> CMP engine also supports the SQL clause ORDER BY in the same EJB-QL<br />

statement, provided it is placed after the WHERE clause. This is done in the standard ejbjar.xml<br />

deployment descriptor in the entity. For example, the following EJB-<br />

QL statement selects distinct objects from a Customer Bean and orders them by the<br />

LNAME field:<br />

<br />

<br />

<br />

findCustomerByNumber<br />

<br />

SELECT Distinct Object(c) from CustomerBean c WHERE c.no > 1000 ORDER<br />

BY c.LNAME<br />

<br />

<br />

You can specify either ASC (ascending) or (DESC) descending in your EJB-QL as<br />

well. If you do not specify either, the results will be ordered ascending by default.<br />

For example, consider the following table:<br />

The query:<br />

Support for GROUP BY<br />

NAME DEPARTMENT SALARY HIRE DATE<br />

Timmy Twitfuller Mail Room 1000 1/1/01<br />

Sam Mackey The Closet with the Light Out 800 1/2/02<br />

Ralph Ossum Coffee Room 900 1/4/01<br />

SELECT OBJECT(e) FROM EMPLOYEE e ORDER BY e.HIRE_DATE<br />

will produce the following result:<br />

NAME DEPARTMENT SALARY HIRE DATE<br />

Timmy Twitfuller Mail Room 1000 1/1/01<br />

Ralph Ossum Coffee Room 900 1/4/01<br />

Sam Mackey The Closet with the Light Out 800 1/2/02<br />

The GROUP BY clause is used to group rows in the result table prior to the SELECT<br />

operation being performed. Consider the following table:<br />

NAME DEPARTMENT SALARY HIRE DATE<br />

Mike Miller Mail Room 1200 11/18/99<br />

Timmy Twitfuller Mail Room 1000 1/1/01<br />

Buddy Coffee Room 1000 4/13/97<br />

Sam Mackey The Closet with the Light Out 800 1/2/02<br />

Todd Whitmore The Closet with the Light Out 900 4/12/01<br />

Ralph Ossum Coffee Room 900 1/4/01<br />

156 BES Developer’s Guide

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!