MySQL custom sort

You are requesting some product on your database and you need to sort results by fixed column values ?
You can use the ORDER BY FIELD() clause.

SELECT * FROM product WHERE product_id IN (4, 2, 8, 9, 5) ORDER BY FIELD(product_id,4, 2, 8, 9, 5)

Leave a Reply