DBAsupport.com Forums - Powered by vBulletin
Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: Sorted Query except one particular row

  1. #1
    Join Date
    Oct 2007
    Posts
    9

    Sorted Query except one particular row

    Can anyone help on this
    A table is having a list of categories and id, the sorted on the categories ,

    but there is record of Others that is to displayed at the end of Query.

  2. #2
    Join Date
    Sep 2002
    Location
    England
    Posts
    7,334
    what?

  3. #3
    Join Date
    Dec 2002
    Location
    Bangalore ( India )
    Posts
    2,434
    you gotta to be clear what your asking for, else the post will be either ignored, rejected or rediculed or all.
    funky...

    "I Dont Want To Follow A Path, I would Rather Go Where There Is No Path And Leave A Trail."

    "Ego is the worst thing many have, try to overcome it & you will be the best, if not good, person on this earth"

  4. #4
    Join Date
    Oct 2007
    Posts
    9
    A table is having a list of catgories

    Categories
    Fashion
    Sports
    Art
    Others


    a Query is to written in such a way that first three should be sorted down alphabetically and fourth is there at it is?

  5. #5
    Join Date
    Nov 2006
    Location
    Sofia
    Posts
    630
    "Query is to written in such a way that first three should be sorted down alphabetically" ?!?!
    Does "in such way" means order by?

  6. #6
    Join Date
    Oct 2007
    Posts
    9
    Yes, query is to order by , but expect the last row, as that should always be the last row in the resultset.

  7. #7
    Join Date
    Nov 2006
    Location
    Sofia
    Posts
    630
    I got it now,
    So you want the data ordered, but OTHERS should always come last, right?
    If so, one solution could be
    Select ...
    from ...
    order by case Category
    when 'Others' then null
    else Category
    end;

    I hope that helps
    Edit: I assume there is no null values in the column

  8. #8
    Join Date
    Dec 2002
    Location
    Bangalore ( India )
    Posts
    2,434
    if you have null then you gotta add one more case condition and with use of analytic functions..

    rgds
    abhay
    funky...

    "I Dont Want To Follow A Path, I would Rather Go Where There Is No Path And Leave A Trail."

    "Ego is the worst thing many have, try to overcome it & you will be the best, if not good, person on this earth"

  9. #9
    Join Date
    Oct 2007
    Posts
    9
    Thanks Bore and abhaysk for your suggestions, but the query Bore you have written did make OTHERS come at the top but not last

  10. #10
    Join Date
    Nov 2006
    Location
    Sofia
    Posts
    630
    order by case Category
    when 'Others' then null
    else Category
    nulls last;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width