开发者

Problem With Sorting in Database

If I run a query like:

select * 
from personaldata 
order by 3

the we get the sorting according to ascending order of the 3rd column, but if I want to sorting according to descending order, then what should the query be? I don't know the name of the 3rd column so i can not write like

select * 
from personaldata 
order by IDPERSONAL desc

I am using MS SQL Server 2000 as my database开发者_运维知识库


You can add desc after the ordinal

select * 
from personaldata 
order by 3 desc

Why wouldn't you know the name of the column though?

Both use of * and column ordinals in the ORDER BY clause are practices to be generally avoided IMO.


select * from personaldata order by 3 desc
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜