Written By:- Isha Malhotra (Software Developer)
Email:-malhotra.isha3388@gmail.com.
Note: -if you find this article helpful then kindly leave your comment
Sorting
of Data in SQL Server
If we want to sort the data on the
particular column in that case we use order by command. We can sort data either
in ascending order or in descending order. By default order by command sorts
data in ascending order.
For
example:-
Check the data of following table:-
Figure 1
Suppose I want to sort data according to
the gender then I will use the following query:-
select * from
Enqdata order by
gender
Note:-by default it sorts data in
ascending order.
After running this query it will
show result as follows:-
If we want to sort data in descending order
then we run the following query:-
select * from
Enqdata order by
gender desc
sorting on the basis of more than one column
suppose if you want to sort the
data on more than one column then we run the following query:-
select * from
Enqdata order by
gender, name
select * from
Enqdata order by
gender desc,
name
in the query it will first sort data on gender basis in ascending order
and after that it will sort it according to name.
but in second query it will first
sort data on gender basis in descendng order and after that it will sort it
according to name in ascending order.
After running this queries you will
see the difference.
No comments:
Post a Comment