The other day I needed to sort a dataset in MySQL and ensure one value was always at the end. However, one of them is “Other”, and I want that one to appear at the end of the list in my UI.
This is what the result of field(name, "Other") looks like for this dataset: | id | name | field | 1 | Backend Developer | 0 | 2 | Designer | 0 | 3 | Other | 1 | 4 | Account Manager | 0 | 5 | Frontend Developer | 0
When we run order by number, letter, MySQL will order by number first, and keep the subsets on their own little islands: | letter | number | | e | 1 | | b | 1 | | d | 2 | | c | 3 | | a | 3 |
Back to our jobs dataset, order by field(name, "Other") will push the “Other” value below.