Mysql order by specific ID values

You can use ORDER BY and FIELD function.
See http://lists.mysql.com/mysql/209784

SELECT * FROM table ORDER BY FIELD(ID,1,5,4,3)

It uses Field() function, Which “Returns the index (position) of str in the str1, str2, str3, … list. Returns 0 if str is not found” according to the documentation. So actually you sort the result set by the return value of this function which is the index of the field value in the given set.

Leave a Comment