I have some simple query:
SELECT * FROM table
You all know the result:
|id| foo | bar |
-------------------------
|1
This way you get id = 3
first:
SELECT *
FROM tbl
ORDER BY (id = 3) DESC
-- ,id
Order by id
additionally if you want the rest ordered, too.
The expression evaluates to boolean. FALSE
(= 0 in mysql) sorts before TRUE
(= 1 in mysql), so we order descending.
It also automatically covers the case of id
being NULL
. I quote the manual again here:
When doing an ORDER BY, NULL values are presented first if you do ORDER BY ... ASC and last if you do ORDER BY ... DESC.