The ORDER BY clause is used to sort the result set by the specified column.
The ORDER BY keyword sort the record in ascending order by default.
If you want to sort the records in descending order, you can use DESC keyword.
If you want to sort the records in descending order, you can use DESC keyword.
The basic syntax is as follows:
SELECTcolumn1, column2, ... column_n FROM tables ORDER BY Column_Name ASC | DESC |
Employee | ||||
Emp_id | Name | Surname | Salary | Dept_id |
1 | Rajesh | Khanna | 45000 | 2 |
2 | Sneha | Gupta | 55000 | 4 |
3 | Sandeep | Nehte | 95000 | 1 |
4 | Kirti | Patil | 25000 | 3 |
5 | Nilesh | Jadhav | 45000 | 3 |
6 | Dipesh | Das | 35000 | 5 |
7 | Kailash | Rane | 62000 | 1 |
8 | Kavita | Deshpande | 48000 | 3 |
9 | Sanjay | Datt | 50000 | 3 |
10 | Shruti | Hasan | 78000 | 1 |
Syntax For SQL:
SELECT Emp_id, Name, Salary, Dept_id FROM employee ORDER BY Salary DESC |
After Execute:
Emp_id | Name | Salary | Dept_id |
3 | Sandeep | 95000 | 1 |
10 | Shruti | 78000 | 1 |
7 | Kailash | 62000 | 1 |
2 | Sneha | 55000 | 4 |
9 | Sanjay | 50000 | 3 |
8 | Kavita | 48000 | 3 |
1 | Rajesh | 45000 | 2 |
5 | Nilesh | 45000 | 3 |
1 | Dipesh | 35000 | 2 |
4 | Kirti | 25000 | 3 |
No comments:
Post a Comment