The MS SQL Server ORDER BY provision is utilized to sort the information in climbing or diving request, in view of at least one sections. Some information base sort question brings about climbing request naturally.
Syntax
Following is the fundamental punctuation of ORDER BY condition.
SELECT column-list
FROM table_name
[WHERE condition]
[ORDER BY column1, column2, .. columnN] [ASC | DESC];
You can utilize more than one section in the ORDER BY condition. Ensure whatever section you are utilizing to sort, that segment ought to be in segment list.
Example
Consider the CUSTOMERS table having the accompanying records −
ID NAME AGE ADDRESS SALARY
1 Ramesh 32 Ahmedabad 2000.00
2 Khilan 25 Delhi 1500.00
3 kaushik 23 Kota 2000.00
4 Chaitali 25 Mumbai 6500.00
5 Hardik 27 Bhopal 8500.00
6 Komal 22 MP 4500.00
7 Muffy 24 Indore 10000.00
Following order is a model, which would sort the outcome in climbing request by NAME and SALARY.
SELECT * FROM CUSTOMERS
ORDER BY NAME, SALARY
The above order will create the accompanying yield.
ID NAME AGE ADDRESS SALARY
4 Chaitali 25 Mumbai 6500.00
5 Hardik 27 Bhopal 8500.00
3 kaushik 23 Kota 2000.00
2 Khilan 25 Delhi 1500.00
6 Komal 22 MP 4500.00
7 Muffy 24 Indore 10000.00
1 Ramesh 32 Ahmedabad 2000.00
Following order is a model, which would sort the outcome in dropping request by NAME.
SELECT * FROM CUSTOMERS
ORDER BY NAME DESC
The above order will deliver the accompanying outcome −
ID NAME AGE ADDRESS SALARY
1 Ramesh 32 Ahmedabad 2000.00
7 Muffy 24 Indore 10000.00
6 Komal 22 MP 4500.00
2 Khilan 25 Delhi 1500.00
3 kaushik 23 Kota 2000.00
5 Hardik 27 Bhopal 8500.00
4 Chaitali 25 Mumbai 6500.00