SQL ORDER BY


The SQL ORDER BY clause is used to sort the data in ascending or descending order, based on one or more columns. Some database sorts query results in ascending order by default.

Syntax:

SELECT column-list 
FROM table_name 
[WHERE condition] 
[ORDER BY column1, column2, .. columnN] [ASC | DESC];

Example

Employee Table
id name dept salary
100 A CSE 25000
101 B CSE 35000
102 C ECE 35000
103 D BBA 20000
104 E MBA 30000
SELECT name, salary FROM employee ORDER BY salary
Output
name salary
D 20000
A 25000
E 30000
B 35000
C 35000

Share this article on