开发者

php/Mysql select order by given ID

开发者 https://www.devze.com 2023-02-16 01:01 出处:网络
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 =

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

精彩评论

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