tags:

views:

21

answers:

2

How can I order my resultset but also have a specific row (with fieldX = Y) be the first one?

+2  A: 

Something like this should work:

ORDER BY (fieldX = Y) DESC, whateverField ASC
Ike Walker
+2  A: 
select tbl.*, if(fieldX = Y, 1, 0) as custom_sort 
from tbl
order by custom_sort desc, fieldZ asc

Now whatever the fieldZ may be, the row with fieldX = Y will always be the first one in the resultset

ovais.tariq
that would work too, but i feel like Ike's solution is cleaner for this purpose.
Garrett