With the ORDER BY clause, the objects and values are placed in order and then the query results are returned. An example of coding the ORDER BY clause is as follows:
SELECT e
FROM Employee AS e
ORDER BY e.monthlySalary DESC |
A description of the ORDER BY clause is as follows:
- If one or more order items are specified, the priority is determined from the left to the right of the orderby item elements and the left-most orderby item has the highest priority.
- The ORDER BY clause is specified when ASC is ascending and DESC is descending. Note that the default value is ASC.
- The SQL rules are applied to the order when the null value exists.
- When the ORDER BY clause is used, the order of the query results is stored in the result of the query method.
For details on the syntax of the ORDER BY clause, see Appendix D BNF for JPQL.
Furthermore, the ORDER BY clause must satisfy the following conditions:
- The order items specified in the ORDER BY clause can be placed in order.
- The order items specified in the ORDER BY clause can be traced from the select expression of the SELECT clause.
If these conditions are not satisfied, an exception might occur in Cosminexus JPA Provider. However, even if an exception does not occur, the operations might not function properly.