MySQL Order By

If you want your 'SQL SELECT' result in a particular order (ascending or descending), than you can specify ORDER BY clause at the end of the statement, which tells the server how to arrange the data returned by the query.

Syntax to use order by:

SELECT * FROM employees ORDER BY emp_name;

The default order of ORDER By is ascending order.

SELECT * FROM employees ORDER BY emp_name ASC;

To arrange the result in descending order.

SELECT * FROM employees ORDER BY emp_name DESC;

Arrange the records in ascending order according to first name, if first name is same in multiple records than result will arrange according to last name.

SELECT * FROM employees ORDER BY first_name, last_name;
SELECT * FROM employees ORDER BY first_name ASC, last_name DESC;