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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -