select *
from employee
order by job asc, name desc;
This will select all the rows and columns from the employee table. They will be sorted according to job in alphabetical order, and if two or more people have the same job, they will be sorted in reverse alphabetical order by name. This will give the following results:
+-------------+---------------+-----------------------+---------------+
| employeeID | name | job | departmentID |
+-------------+---------------+-----------------------+---------------+
| 9842 | Ben Smith | DBA | 42 |
| 7513 | Nora Edwards | Programmer | 128 |
| 6651 | Ajay Patel | Programmer | 128 |
| 9006 | Candy Burnett | Systems Administrator | 128 |
+-------------+---------------+-----------------------+---------------+
4 rows in set (0.02 sec)
If you just specify ORDER BY column with no ASC or DESC, the default is ASC. Note that if ORDER BY is not specified, you can't assume anything about the order in which rows will be returned.
No comments:
Post a Comment