How to Sort Result Set of Select Query in MySQL

Notes:

How to sort result set of select query in MySQL:
How to sort records in the resultant table of the select query:
- To sort records in the resultant table of the select query; we take help order by clause.
- order by clause sorts records in the resultant table of the select query based on the given column(s) in the ascending or descending order.
- asc keyword is used to sort records in ascending order.
- desc keyword is used to sort records in descending order.

Basic Syntax:
select * from tablename order by column_name1[, column_name2… [ asc / desc ]];

Ex:
select * from tbl_faculty order by name asc;
- It returns all records from the tbl_faculty table; sorted by the name column in ascending order.

select * from tbl_faculty order by name desc;
- It returns all records from the tbl_faculty table; sorted by the name column in descending order.

Interview Questions: