order by value mysql 1

order by value mysql

SELECT * FROM mytable WHERE id IN (1,2,3,4) ORDER BY FIELD(id,3,2,1,4);

# or
SELECT * FROM mytable ORDER BY FIELD(field_name,'value1','vaue2','etc');

Here is what the above code is Doing:
1. The FIELD() function returns the index position of a value in a list of values.
2. The ORDER BY clause sorts the rows based on the index position returned by the FIELD() function.
3. The IN operator allows you to specify multiple values in a WHERE clause.

Similar Posts