Skip to Navigation

Arbitrary ordering in MySQL

Posted in:

Suppose you want to order some sql results in an arbitrary order. How would you do that?

Use ORDER BY FIELD:

SELECT * from test WHERE OrderID IN (10,5,9)
order by field(OrderID,10,5,9)

Thanks to Rudy for this one.