tags:

views:

68

answers:

2

Is there a way I can return a set of mySQL rows in the order they're called. For instance, when I call this:

SELECT * FROM heroes WHERE id IN ( 41 , 48 , 38 , 14 , 47 , 44 ) LIMIT 6

I'd like the rows returned in that order. Is there a php function I could apply to the results afterward to achieve this ordering?

A: 

You could try ORDER BY FIELD(id, 41, 48, 38, 14, 47, 44) ASC.

EDIT: Found a better function than FIND_IN_SET.

Matthew
A: 

Yes, take a look at "Ordering by the order of values in a SQL IN() clause" answers. The solution is very well described there.

Ivan Nevostruev
Beautiful. Thanks!
Bjork24