August 17, 2009 at 7:46 am
hi friends
in SQL2005 when i order by a select with more than one column it does not work
whats wrong ?
SELECT Record.Date,Record.[Time],Record.Tone,Record.Telephone
From Record
Order By Record.Date,Record.[Time] DESC
in above statement,result will order by just time desending !!!
August 17, 2009 at 8:11 am
Can't see any reason why it won't work, unless all the rows have the same value for Date.
Table definitions and sample data? (http://www.sqlservercentral.com/articles/Best+Practices/61537/)
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 17, 2009 at 8:20 am
when i select as below ,all thing is correct :
SELECT Record.Date,Record.[Time],Record.Tone,Record.Telephone
From Record
Order By Record.Date DESC,Record.[Time] DESC
I mean putting DESC for every part of order by !
August 17, 2009 at 8:37 am
dr_csharp (8/17/2009)
I mean putting DESC for every part of order by !
If you want to order by both descending, that's how it has to be done. If you specify
ORDER BY Col1, Col2 DESC then you're saying sort by Col1 ascending and Col2 descending.
Ascending is the default if nothing's specified. Your initial query was equivalent to this
SELECT Record.Date,Record.[Time],Record.Tone,Record.Telephone
From Record
Order By Record.Date ASC,Record.[Time] DESC
Your description of the problem seemed to say it wasn't ordering by date at all.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply