MySQL specify arbitrary order by id -
is possible specify arbitrary order mysql select
statement? e.g.,
select * table_name id in (1, 3, 2, 9, 7) order (1, 3, 2, 9, 7);
the order of numbers listed directly after in
not seem matter.
find_in_set function trick
select * table_name id in (1, 3, 2, 9, 7) order 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 lack of spaces in string argument of find_in_set function.
Comments
Post a Comment