Reputation: 1628
I am fetching 50 ids from my database table. I want a particular id say 15 at the top and all the others after that. How can i do this using SQL query?
$sql = mysql_query("Select id from USERS");
I searched a lot but didn't find anything about this subject.I don't want to use two queries.
Upvotes: 3
Views: 307
Reputation: 780673
SELECT id
FROM USERS
ORDER BY id != 15, id
id != 15
will be 0
when id
is 15, and 1
for all other values, so that row will be first. The remaining rows will be ordered by the id
s.
Upvotes: 5