MySQL specify arbitrary order by id
问题 Is it possible to specify an arbitrary order for a MySQL SELECT statement? E.g., SELECT * FROM table_name WHERE id IN (1, 3, 2, 9, 7) ORDER BY (1, 3, 2, 9, 7); The order of the numbers listed directly after IN do not seem to matter. 回答1: FIND_IN_SET function will do the trick SELECT * FROM table_name WHERE id IN (1, 3, 2, 9, 7) ORDER BY FIND_IN_SET(id, '1,3,2,9,7'); http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set EDIT: Note the lack of spaces in the string