Some tricks
suggest changeORDER BY FIND_IN_SET(card_type, "MASTER-CARD,VISA,DISCOVER") -- sort 'MASTER-CARD' first.
ORDER BY x IS NULL, x -- order by `x`, but put `NULLs` last.
Custom ordering
SELECT * FROM some_table WHERE id IN (118, 17, 113, 23, 72)
ORDER BY FIELD(id, 118, 17, 113, 23, 72);
Returns the result in the specified order of ids.
id| …|
—— | —— |
118 | …|
17 | …|
113 | …|
23 | …|
72 | …|
Useful if the ids are already sorted and you just need to retrieve the rows.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents