Sunday, October 5, 2014

What is the impact to use of desc, asc or none of them?


SQL Query without any ordering:


if you don’t specify, by default it’s a ascending order. [1,2,3… a,b,c]

select Name
  ,CountryRegionCode,
  ROW_NUMBER() over (order by Name)
from
  Sales.SalesTerritory

Output of the above query:



SQL Query with Ascending order: [1,2,3… a,b,c]


select Name
  ,CountryRegionCode,
  ROW_NUMBER() over (order by Name)
from
  Sales.SalesTerritory
order by
  Name asc

Output of the above query:



SQL Query with Descending order: [3,2,1… z,y,x….]


select Name
  ,CountryRegionCode,
  ROW_NUMBER() over (order by Name)
from
  Sales.SalesTerritory
order by
  Name desc

Output of the above query:


No comments:

Post a Comment