Comments Feed
Sep
18

Sorting MySQL Result by field

After my post about sorting multidimensional array's by an array of values I've now found a better way of keeping a mysql result set in order by using the ORDER BY FIELD() function. For example:

SELECT id,name FROM tbl_name ORDER BY FIELD(id,3,4,2,6,8,1) DESC

Will return the results in the correct order or using ASC instead of DESC will return results in reverse order.

The folks over at MySQL have thought of everything

posted by Mark Willis
Tags:

Leave a Reply