Amardeepvijay
Amardeepvijay

Reputation: 1628

get particular id at the top and other after

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

Answers (1)

Barmar
Barmar

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 ids.

Upvotes: 5

Related Questions