I hope there\'s a simple solution for this:
I have a table where each row has it\'s own status (SET
type field). Statuses can be:
SELECT * FROM table ORDER BY FIELD(status,'offline','available','busy','distance')
see Mysql order by specific ID values
You could also do something like this, if reordering the SET
values in impractical:
... ORDER BY CASE `status`
WHEN 'available' THEN 1
WHEN 'busy' THEN 2
WHEN 'distance' THEN 3
WHEN 'offline' THEN 4
END
Thought I'd add another way to order by custom field values,
ORDER BY FIND_IN_SET(status, 'available,busy,distance,offline')
(If the given strings contain a quote simply escape it)
Nevermind.
The trick is saving SET
values at the right order.
Simpler than the solutions above:
ORDER BY CONCAT(status)