Sorting

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OuTCasT
    Contributor
    • Jan 2008
    • 374

    Sorting

    I have been asked to rearrange the data in a table to display from

    Region Contacts
    ---------------------------------------
    Cape Town John
    Cape Town Ruby
    Cape Town Anna
    Durban Joe
    Durban Allison
    Johannesburg Derrick


    To This

    Region Contacts
    ----------------------------------------
    Durban Joe
    Durban Allison
    Johannesburg Derrick
    Cape Town Anna
    Cape Town Ruby
    Cape Town John
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    I can't see any logical order in your example.
    Can you be more specific?

    Comment

    • OuTCasT
      Contributor
      • Jan 2008
      • 374

      #3
      They gave me 2 columns to sort...
      Region and Contacts

      That is what is on the sheet, the original is the top data, now they said write sql query to rearrange the data in the new order which is at the bottom.

      I dunno if that is possible. I also looked and there is no logical order of the data.

      Kind Regards
      D.Kruger

      Comment

      • nbiswas
        New Member
        • May 2009
        • 149

        #4
        Solution to Sorting

        The closest I can think of is

        Code:
        select Region,Contacts from @t  where region not like '% %'
        union all
        select Region,Contacts from @t  where region like '% %'
        Output:

        Code:
        Region	Contacts
        Durban	Joe
        Durban	Allison
        Johannesburg	Derrick
        Cape Town	John
        Cape Town	Ruby
        Cape Town	Anna

        Comment

        Working...