is it possible to order a select from mysql by using a known id first.
Example:
$sql = "SELECT id, name, date FROM TABLE ORDER BY "id(10)", id D开发者_C百科ESC
Not sure if the above makes sense but what I would like to do is first start ordering by the known id which is 10 which I placed in quotes "id(10)". I know that cannot work as is in the query but it's just to point out what I am trying to do.
If something similar can work I would appreciate it. Thanks.
SELECT id, name, date
FROM tbl
ORDER BY CASE WHEN id = 10 THEN 0 ELSE 1 END, id DESC
How about this?
SELECT id, name, date, IF(id = 10, 1, 0) AS sort_field
FROM TABLE
ORDER by sort_field, id DESC
精彩评论