MySQL Tutorial – MySQL Order BY Clause

MySQL TutorialMySQL Order BY Clause

The ORDER BY clause is used to sort the records in the result set specified by a column name. You can sort the record in ascending (ASC) or descending (DESC) order.

ASC – ascending order (default)
DESC – descending order

ORDER BY syntax:

SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC;

Let’s see some example of ORDER BY clause:

Here is our database table: (employee_record)


We are going to select the f_name and l_name and sort it according by l_name. To do that, issue the command:

SELECT f_name, l_name
FROM employee_record
ORDER BY l_name;


| f_name     | l_name  |
| Rolan      | Algara  |
| John Lloyd | Cruz    |
| Sam        | Milby   |
| Piolo      | Pascual |
| John       | Prats   |
| Jericho    | Rosales |
6 rows in set (0.11 sec)
, , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.