Ordering (ORDER BY)

You can order the SELECT query results in ascending or descending order, based on one or several columns using the ORDER BY SQL operator. 

You specify the names of the columns that should be used for ordering. For each column, you specify how you want the records to be sorted by adding ASC or DESC order specifier. ASC means sorting in ascending order. DESC means the descending order. In SQL, if nothing is specified, ascending order is assumed.

In the following example, we fetch the records from the employees database. We want to display employee's name, salary, and age. We sort the records by name (in ascending order), then we sort records by salaries (in descending order).

SELECT e.name, e.salary, e.age
FROM employees e
ORDER BY e.name ASC, c.salary DESC;

This query is equivalent to the following QueryDSL:
 
selectFrom(employees)
    .orderBy(employees.name.asc(), employees.salary.desc())
    .list(employees.name, employees.salary, employees.age);

In QueryDSL, you specify the sorting order by specifying asc(), or desc() for each column in the orderBy() list.