Take the 2-minute tour ×

I have a sql statement that brings back ids. Currently I am ordering the id's with the usual "ORDER BY id". What I need to be able to do is have the query order the first 3 rows by specific id's that I set. The order the remaining as it is currently. For example, I want to say the first 3 rows will be id's 7,10,3 in that order, then the rest of the rows will be ordered by the id as usual.

right now i just have a basic sql statement...

SELECT * from cards ORDER BY card_id
share|improve this question

2 Answers 2

up vote 3 down vote accepted

A bit shorter than Quassnoi's query, with FIELD :

-- ...
ORDER BY FIELD(card_id, 3, 10, 7) DESC

You have to invert the order because of the DESC, I didn't find a way to do it more naturally.

share|improve this answer
+1, a nice one. –  Quassnoi Aug 15 '11 at 7:58
FROM    cards
        CASE card_id WHEN 7 THEN 1 WHEN 10 THEN 2 WHEN 3 THEN 3 ELSE 4 END,
share|improve this answer
great, thanks. That helped a lot. –  Brian Aug 15 '11 at 2:06

Your Answer


