SELECT id, name FROM table WHERE id IN (2,4,3,1);And I want the result to be sorted by the order specified in the IN clause. In order to do this, simply modify the query like the following:
SELECT id, name FROM table WHERE id IN (2,4,3,1) ORDER BY FIELD (id, 2,4,3,1);The FIELD function returns the position of the first string in the remaining list of strings. Hope this would help someone like me.