tags:

views:

33

answers:

2

i have a table called customer

Name   Id
----- ----

vimal 34

arun  56

sasi  98

if i need to arrange those data in an alphabetical order we usually use query "select * from customer where order by name asc " similarly to reverse we use the query "select * from customer where order by name desc " without use of asc and desc keyword how to arrange or reverse the data's

A: 

Without using an ORDER BY clause the order of the returned data is completely arbitrary; it's whatever is most convenient for the server. You can drop the ASC as this is the default.

Mark Ransom
+1  A: 
;with cte as
(
select Id, name, row_number() over (order by name) rn 
from customer  
)
select Id, name
from cte 
order by rn /* (Or use -rn to sort descending)*/
Martin Smith