Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2006
    Posts
    15

    Unanswered: sorting but always having specified fields come up first

    is there a way to sort by a field, but have specified fields always appear first?

    e.g.:

    ID | DATA
    1 | ...
    2 | ...
    3 | ...
    4 | ...
    8 | ...
    10 | ...

    I want to retrieve all records ordered by ID ascending, but I want records 8 and 10 to always be first, so the retrieval looks like:

    ID | DATA
    8 | ...
    10 | ...
    1 | ...
    2 | ...
    3 | ...
    4 | ...

    I know it sounds kind of dumb, but it's kind of the way it is for now. any way to do this without having to use multiple queries?

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    order
        by case when id in (8,10) then 0 else 937 end
         , id
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Oct 2006
    Posts
    15
    worked perfectly. thanks!

Posting Permissions

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