My situation is a bit more complicated than order-by-enum-field-in-mysql
My SQL is:
SELECT `a`.`ChannelID`,
`a`.`CategoryID`,
`a`.`Country`,
`a`.`LocalName`,
if((`a`.`Type` = 'FreeText'
AND a.IsHybrid = 'YES'), 'Hybrid',
if(`a`.`Type` = 'FreeText'
AND a.IsHybrid = 'NO', 'FreeText', a.Type)) AS TYPE,
`a`.`IsHybrid`
FROM `ProCatCountry` AS `a`
INNER JOIN `ProCat` AS `b` ON a.CategoryID = b.CategoryID
ORDER BY FIELD(a.TYPE, 'FreeText', 'Hybrid', 'Structured') ASC
But the order is not correct, first FreeText
records appeared then Hybrid
then FreeText
appeared again.
Field TYPE
is enum, and I want to order by this field, meanwhile, a value which does not included in enum list - the calculated one called Hybrid
should also be ordered by correctly. How can I do with this situation?
Originally, there was a TYPE
field ambiguous error, thanks to @Jens, after changed to a.TYPE
, the ambiguous error was resolved.