I understand the normal ASC and DESC ORDER BY clause.
However, I have a case where table contains a column unitType where unitType can be 0, 1 or 2. I need to sort my result set so that the rows returned are in a particular order depending the value of the unitType column.
This is the closest I have gotten:
SELECT * FROM `units` WHERE `unitType`=0
union
select * from units where unitType=2
union
select * from units where unitType=1
This lists my rows with unitType=0, followed by those with value 2 and finally 1. Is there a better way to do this? I need to alter this query to fetch rows in any particular order e.g. 2, 0, 1 etc.
1 Answer