MySQL ORDER BY

Last Updated: March 11, 2022

ORDER BY is used to sort the record set by ascending order or descending order.

    SELECT column1,column2 
    FROM tablename  
    [WHERE conditions]  
    ORDER BY column1,column2 [ ASC | DESC ];  

Sort the record set by age

SELECT name FROM employees where age > 40 ORDER BY name ASC

If you omit the ASC it gives the same result

SELECT name FROM employees where age > 40 ORDER BY 

Sort the results in descending order

SELECT name FROM employees where age > 40 ORDER BY name DESC

You can use more than one column name after the ORDER BY clause

Test