tags:

views:

40

answers:

2

Hi, 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 DESC

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.

+3  A: 
  SELECT id, name, date 
    FROM tbl 
ORDER BY CASE WHEN id = 10 THEN 0 ELSE 1 END, id DESC
Tomalak
Thank you, this works great
markj
A: 

How about this?

SELECT id, name, date, IF(id = 10, 1, 0) AS sort_field
FROM TABLE
ORDER by sort_field, id DESC
David M
This also was useful, thanks.
markj