php/Mysql select order by given ID
I have this variable
$id = 12;
I want to select all rows from my table in any order but with the row with id = 12 as the 开发者_运维知识库first result. How can I do this?
SELECT ... ORDER BY id = 12 DESC, id
You could select first the ones with id=12 and then the others (id!=12). With an index on id, it shouldn't be slower than requiring the whole table one time.
精彩评论