Is it possible to do a SELECT statement with a predetermined order, ie. selecting IDs 7,2,5,9 and 8 and returning them in that order, based on nothing more than the ID field?
Both these statements return them in the same order:
SELECT id FROM table WHERE id in (7,2,5,9,8)
SELECT id FROM table WHERE id in (8,2,5,9,7)
I didn’t think this was possible, but found a blog entry here that seems to do the type of thing you’re after:
will give different results to
FIND_IN_SETreturns the position ofidin the second argument given to it, so for the first case above,idof 7 is at position 1 in the set, 2 at 2 and so on – mysql internally works out something likethen orders by the results of
FIND_IN_SET.