tags:

views:

52

answers:

2

Hello

I wish to order a table:

Firstly by Field1=3 Then by Field2 DESC

I know I can't write OrderBy Field1=3, Field2 DESC

So how can I implement this??

TO CLARIFY:

Let's say I have a table of books. I wish to list ALL the books in the table. I wish the books from 1990 to appear at the top, then the rest of the books in alphabetical order of title.

+1  A: 

This is TSQL rather than MySQL, but it should give you the idea...

(Assuming I understand your question...)

ORDER BY
    CASE WHEN Field1 = 3 THEN 0 ELSE 1 END    ASC,
    Field2                                   DESC
Dems
+7  A: 

Actually, you can write the statement you said you can't. Using your clarification example:

SELECT * FROM Books ORDER BY (year = 1990) DESC, name

"year = 1990" will be "1" for ones where year is 1990, so those will go at the top.

Chad Birch
Works perfectly, thank you sir.