Pages

Showing posts with label SQL ORDER BY. Show all posts
Showing posts with label SQL ORDER BY. Show all posts

How to use ORDER BY?

ORDER BY operator is used to sort result of a SELECT statement.
It is used with 2 options:
  • ASC - ascending order (it is default, you can ignore writing it)
  • DESC - descending order

Example: Select employees from employee table and sort employee names in alphabetical order.

SELECT * FROM tableEmployee ORDER BY employeeName ASC

Select employees sort them by employee names in ascending order, but by birthday in descending order.

SELECT * FROM tableEmployee ORDER BY employeeName ASC, employeeBirthday DESC