how use oderby with different columns

  • i have a table like..

    column1 column2 column3

    a a 002

    a a 003

    a a 001

    b b 002

    b b 003

    b b 001

    i need like this.....

    column1 column2 column3

    a a 001

    a a 002

    a a 003

    b b 001

    b b 002

    b b 003

    help me.....

  • Hi,

    Desired order by is not possible or you post the wrong output.

    However, you just use the normal order by class

    Select * from MYTABLE

    Order by col1, col2, col3

    col1|col2|col3

    A|A|001

    A|B|002

    A|C|003

    B|A|003

    B|B|001

    B|C|002

  • What have you tried so far?

    Did you check the examples in BOL (Books Online, the SQL Server help system installed together with SQL Server)?

    You might want to look for "Sorting Rows", Subtitle: "Sorting Rows with ORDER BY"...



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • select * from [table_name] order by column1, column2,column3 should work (even if all the column datatype if varchar)

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

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