do you want find_in_set function
$list = "1,2,....";
$sql = "select * from table where id in($list) order by find_in_set($id, '$list')";
another (possibly faster) option is to sort in php:
$list = array(2, 3, ...);
$s = implode(',', $list);
$sth = mysql_query("select * from table where id in($s)");
$rows = array();
while($r = mysql_fetch_object($sth))
$rows[$r->id] = $r;
$sorted_rows = array();
foreach($list as $id)
$sorted_rows[] = $rows[$id];
source
share