ORDER BY FIELD with a wilcard?
mysql, sql
Solution
Use an `ORDER BY CASE` construct. It forces a 0 for the value you want to extract, and 1 for everything else, so the 0 sorts first. It just fits into the `ORDER BY` list like any column, comma-separated, so you can add additional sort columns afterward.
ORDER BY
CASE WHEN myField = 'ttt3' THEN 0 ELSE 1 END,
myField,
other_order_col,
other_order_col2
Problem
Basically I have a field that can contain some prefixed strings: ``` word1 bla2 ttt3 word4 [...] ``` I need to order SQL with for example `ttt3` first and then all other string after. I tried this with no luck ``` ORDER BY FIELD (myField,'ttt3',*) ``` Any suggestions?