Order by specific word, then alphabetically

  • I have a lot of parameters in a table. I query the database to popuplate dropdown boxes with specific options. Some dropdowns have an option "OTHER". How do I query the database to return "OTHER" as the first option, and then sort alphabetically? eg:

    Select your gender:

    OTHER

    MALE

    FEMALE

    Right now I only know how to order asc or desc or as the data was entered by ordering by the ID. Is there a way of doing what I want to do? I'm using SQL 2008 Enterprise.

  • Something like this:

    ORDER BY CASE WHEN Col='Other' THEN 1 ELSE 2 END, Col

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

  • Thank you! Worked like a charm!

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

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