Get a specific id at the top and another after

I am retrieving 50 IDs from my database table. I want a specific id to say 15 at the top and everyone else after that. How can I do this with a SQL query?

$sql = mysql_query("Select id from USERS");

      

I searched a lot but didn't find anything about this question. I don't want to use two queries.

+3


source to share


1 answer


SELECT id
FROM USERS
ORDER BY id != 15, id

      



id != 15

will be 0

when id

equal to 15, and 1

for all other values, so the line will be the first. The rest of the lines will be ordered using id

s.

+5


source







All Articles