开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜