Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 order by 1 / order by 2 / ... / order by n

Author  Topic 

m1k3ch3ck
Starting Member

7 Posts

Posted - 2012-06-08 : 07:22:07
i have an assumption and i'd like to see if i am correct:

"order by n" orders my query by the selected value number n, e.g.:

select name, age, color
...
order by 1
>> orderes (alphabetic) by name

...
order by 2
>> orderes (numeric) by age

...
order by 3
>> orderes (alphabetic) by color


question:
is this correct ?

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-06-08 : 07:38:26
quote:
Originally posted by m1k3ch3ck

i have an assumption and i'd like to see if i am correct:

"order by n" orders my query by the selected value number n, e.g.:

select name, age, color
...
order by 1
>> orderes (alphabetic) by name

...
order by 2
>> orderes (numeric) by age

...
order by 3
>> orderes (alphabetic) by color


question:
is this correct ?

Yes, if name and color are character type columns and age is numeric type column. If age were to be character type, the ordering would be alphanumeric for that.

When you specify order by n, it simply is telling SQL Server to order it by the n'th column in in the select list.
Go to Top of Page

m1k3ch3ck
Starting Member

7 Posts

Posted - 2012-06-08 : 07:39:17
thx
Go to Top of Page
   

- Advertisement -