How to sort ENUM column in MySQL database?
Use:
ORDER BY CASE color
WHEN 'YELLOW' THEN 1
WHEN 'RED' THEN 3
ELSE 2
END, name
This works fine with mysql. But for h2 DB it throws an error
Caused by: org.h2.jdbc.JdbcSQLException: Order by expression "CASEWHEN((color = 'YELLOW'), 1, CASEWHEN((color = 'RED'),3))" must be in the result list in this case; SQL statement:
To avoid the error add the stmt CASEWHEN((color = 'YELLOW'), 1, CASEWHEN((color = 'RED'),3))
in the select clause.