Actually, this is better:
SELECT * FROM your_table
WHERE id IN (5,2,6,8,12,1)
ORDER BY FIELD(id,5,2,6,8,12,1);
heres the FIELD documentation:
http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_field
More Related Contents:
- Recreating a query using INNER JOIN? [duplicate]
- MySQL – UPDATE query based on SELECT Query
- MySQL: is a SELECT statement case sensitive?
- Create a temporary table in a SELECT statement without a separate CREATE TABLE
- MySQL SELECT WHERE datetime matches day (and not necessarily time)
- MySQL Query – Records between Today and Last 30 Days
- Ordering by specific field value first
- SELECT / GROUP BY – segments of time (10 seconds, 30 seconds, etc)
- INSERT INTO…SELECT for all MySQL columns
- Combine Multiple child rows into one row MYSQL
- #1139 – Got error ‘repetition-operator operand invalid’ from regexp
- MySQL select statement with CASE or IF ELSEIF? Not sure how to get the result
- Checking multiple columns for one value
- MySQL difference between two rows of a SELECT Statement
- MySQL – How to search for exact word match using LIKE?
- MySQL #1093 – You can’t specify target table ‘giveaways’ for update in FROM clause
- MySQL How do you INSERT INTO a table with a SELECT subquery returning multiple rows?
- How do I get the first day of the week of a date in mysql?
- MySQL error 1241: Operand should contain 1 column(s)
- quick selection of a random row from a large table in mysql
- Converting SELECT DISTINCT ON queries from Postgresql to MySQL
- mysql select sum group by date
- SELECT query return 1 row from each group
- MySQL – SQL_BIG_SELECTS
- Comma separated string of selected values in MySQL
- MySQL Select Query – Get only first 10 characters of a value
- SELECT INTO Variable in MySQL DECLARE causes syntax error?
- MySQL Error: #1142 – SELECT command denied to user
- MySQL Select Multiple VALUES
- mySQL returns all rows when field=0