Sql order by

The ORDER BY keyword is used to get data order wise. Data can be arranged in ascending or descending order
Syntax is as:
SELECT * FROM table_name WHERE [ column_name condition ] ORDER BY column_name [ASC|DESC]
ASC is used for ascending order and DESC is used for descending. We can use ORDER BY for more than one column.
WHERE [ column_name condition ] is optional.As we have table employees.

id first_name last_name salary city
1 Johan Sumith 200000 Delhi
2 Ansh Kumar 300000 Mumbai
3 Sameer Seth 100000 Delhi
4 Pyush 250000 Kolkata
5 Shikha Anand 160000 Chandigarh
6 Rajeev Khatri 450000 Chennai
7 Ram Kumar 540000 Amritsar
8 Ritu Sharma 500000 Sonepat
9 Deepika Verma 360000 Chandigarh
10 Kuldeep Singh 270000 Simla



We want to arrange employees salary wise in descending order.
SELECT * FROM employees ORDER BY salary DESC

We get
id first_name last_name salary city
7 Ram Kumar 540000 Amritsar
8 Ritu Sharma 500000 Sonepat
6 Rajeev Khatri 450000 Chennai
9 Deepika Verma 360000 Chandigarh
2 Ansh Kumar 300000 Mumbai
10 Kuldeep Singh 270000 Simla
4 Pyush 250000 Kolkata
1 Johan Sumith 200000 Delhi
5 Shikha Anand 160000 Chandigarh
3 Sameer Seth 100000 Delhi

Arranging employees' data with first_name in ascending order and salary in descending order.
SELECT * FROM employees ORDER BY first_name ASC,salary DESC

idfirst_namelast_namesalarycity
2AnshKumar300000Mumbai
9DeepikaVerma360000Chandigarh
1JohanSumith200000Delhi
10KuldeepSingh270000Simla
4Pyush(null)250000Kolkata
6RajeevKhatri450000Chennai
7RamKumar540000Amritsar
8RituSharma500000Sonepat
3SameerSeth100000Delhi
5ShikhaAnand160000Chandigarh