I'm busy writing a PHP app that gets data from a database, but I need to get the data in a certain order.
My Query looks as follows
$sql = "select id,title,type from campaigns where id=$cid order by type";
Now my problem is these are the different types 'GC','MJ','MU','MS','MW','MX','GS' and I want MX to always be select last, thus should always be at the end of the row. So the others shpould firstly be selected and then MX. I hope this makes sense.
You can sort like this:
ORDER BY IF (type = 'MX', 1, 0), type
(select id,title,type from campaigns where id=$cid and type <> 'MX' order by type)
UNION
(select id,title,type from campaigns where id=$cid and type ='MX')
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