Reputation: 89
For example:
id 1,2,3,4,5,6,7,8,9,10
I want to show first id = 7
and after 10,9,8,6,5,4,3,2,1
. How to write this code with php ? Please help me (Sorry for bad English)
Upvotes: 4
Views: 54
Reputation: 1269763
MySQL has a convenience where boolean expressions are treated as integers, with "1" for true and "0" for false. A fast way to write this is:
order by (id = 7) desc, id desc
In other databases, you need to use case
or similar logic.
Upvotes: 4
Reputation: 311308
You could order by a specific case
expression:
SELECT *
FROM mytable
ORDER BY CASE id WHEN 7 THEN 0 ELSE 1 END ASC, id DESC
Upvotes: 1