Suppose I have the following query:
SELECT id, name FROM table ORDER BY name
How would I throw a particular name to the front of the order and then do the rest of the ordering, something like:
SELECT id, name FROM table ORDER BY name='david', name
You are almost exactly there. You just need desc
:
SELECT id, name
FROM table
ORDER BY (name = 'david') DESC, name;
MySQL treats booleans as integers, with true being "1" and false being "0". So, when it is true, the value is a "1". To put it first, you need to sort in descending order.
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