Possible Duplicate:
MySQL Query to pull items, but always show a certain one at the top
Hi I have a number of items in a database table.
At the moments they're sorted by name.
But I have one item with ID 12 which I would like to always be first in the line.
Is this possible in an easy way?
You can do
ORDER BY (id = 12) DESC, someOtherColumn
This will order by whether id
equals 12
first (resulting in either 0
or 1
, hence the DESC to put the positive results first), then any other column(s) you may specify for sorting.
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