Skip to content
Advertisement

MySQL put a specific row at the top of the result

I’m doing a basic SQL select query which returns a set of results. I want a specific row which the entry “Fee” to be put at the top of the results, then the rest.

Something like:

SELECT * FROM tbl ORDER By Charges = Fee DESC, Charges DESC

Can anyone help?

Advertisement

Answer

You could try this :

SELECT * from tbl ORDER BY CASE WHEN Charges = 'Fee' THEN 0 ELSE 1 END, Charges DESC;
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement