MySQL: Ordering values according to a predefined pattern

The Solution

SELECT * FROM `tablename`  WHERE  `id_record` IN (1,2,3,4,5,6,7,8,9,10,11) ORDER BY FIELD (`id_record`,5,4,6,3,2,1,7,9,8,10,11 )

As you can see from the code above ,we are using one more MySQL keyword called FIELD and inside the bracket we are passing the first parameter as the field name `id_record.`You can then order the records in the resultset.

Note : Do not put any space between FIELD and () , else it will throw error while executing this in PHP with mysql_query()

150 150 Burnignorance | Where Minds Meet And Sparks Fly!