What Is Order By Keyword in SQl SERVER ? How To use?
Order by :-
-The Order by keyword is used to sort the result according to user choice ascending order or descending order.
-By default order by show ascending order result.
Syntax:-
Select * from Table_name
order by columnname ASC/DESC
CASE:
1) By Ascending Order:- The following SQL statement selects all Student from the "student" table, sorted ASCENDING by the "Name" column:
Example:-
Select * from Student
Order by Name ASC
2)By Descending Order:- The following SQL statement selects all Student from the "student" table, sorted DESCENDING by the "Name" column
Example:
Select * from Student
Order by Name DESC
3)Show Some Column:- The following SQL statement selects some column from the "student" table, sorted ASCENDING by the "Name" column:
Example:-
Select Name, City From Student
Order by Name ASC
4)Order by Mutiple Column:- The following SQL statement selects all Student from the "student" table, sorted ASCENDING by the "Name" column and DESCENDING by the "City" Column:
Example:-
Select * From Student
Order by Name ASC , City DESC