order by for 3 columns

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • user1980
    New Member
    • Dec 2009
    • 112

    order by for 3 columns

    hello there,

    I have 3 columns which I have to sort.
    My data is

    -List Item

    - Albany 22 194
    - Anchorage 24 194
    - Canada 38 34
    - Carbondale 40 194
    - China 51 40
    - Des Moines 61 194
    - England / UK 307 193
    - France 69 66
    - Hong Kong 83 84
    - Mexico 308 123
    - Nashville 119 194
    - Russia 310 153
    - Singapore 172 165

    I want the data to be sorted as

    1. Albany 22 194

    Anchorage 24 194

    Carbondale 40 194

    Des Moines 61 194

    Nashville 119 194

    Canada 38 34

    China 51 40

    England / UK 307 193

    France 69 66

    Hong Kong 83 84

    Mexico 308 123

    Russia 310 153

    Singapore 172 165

    I tried to use the order by CASE but could not achieve it. can somebody please help me.
    thanks in advance.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    What's the category for sorting?


    -- CK

    Comment

    • user1980
      New Member
      • Dec 2009
      • 112

      #3
      the last column has to be in decreasing order and then..first row has to be in alphabetical order..for all the values where column three is not 194, have to be arranged in ascending order.....am I clear?
      let me put it in other words, the values of 3rd column have to be sorted as all 194s first and then the rest of them in ascending order....please let me know if i am not clear..

      Comment

      • user1980
        New Member
        • Dec 2009
        • 112

        #4
        thank you CK for the reply..

        i got the desired results using union statement..

        Comment

        • ck9663
          Recognized Expert Specialist
          • Jun 2007
          • 2878

          #5
          you can also try

          Code:
          SELECT....
          
          FROM...
          
          WHERE...
          
          ORDER BY case when COL3 = 194 then 0 else 1 end,  COL1, COL2
          Happy Coding!!!

          --- CK

          Comment

          Working...