Let's say I have this MySQL query:
SELECT * FROM A WHERE x='abc' OR y=0;
How can I prioritize the rows so that cases where x='abc'
are ordered FIRST? If y=0
but x!='abc'
, I want those rows to come after cases where x='abc'
.
Can this be accomplished with a simple ORDER BY clause?
Thanks!
SELECT *
FROM A
WHERE x='abc'
OR y=0
order by case when x='abc' then 0 else 1 end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With