select with order by multi column

  • 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 !!!

  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • 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 !

  • 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

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply