You can use the function FIELD
:
FIELD(str,str1,str2,str3,...)
Returns the index (position) of str
in str1, str2, str3,... list. Returns 0 if str
is not found.
Example:
SELECT * FROM produtos WHERE id IN (1, 2, 3, 4) ORDER BY FIELD(id, 4, 2, 1, 3);
See demonstração
Your SQL command looks like this:
SELECT * FROM produtos
WHERE id IN
(144,140,134,133,128,129,141,143,149,150,147,146,126,142,125,99,100,92,91,90,108,109,123,124,122,121,110,89)
ORDER BY FIELD
(id, 144,140,134,133,128,129,141,143,149,150,147,146,126,142,125,99,100,92,91,90,108,109,123,124,122,121,110,89);
And what an order you’d like to apply?
– Rafael Withoeft
the order I specified in..
– Ale
Try so using the
Field
:SELECT * FROM produtos WHERE id in(144,140,134,133,128,129,141,143,149,150,147,146,126,142,125,99,100,92,91,90,108,109,123,124,122,121,110,89) ORDER BY FIELD(id, 144,140,134,133,128,129,141,143,149,150,147,146,126,142,125,99,100,92,91,90,108,109,123,124,122,121,110,89);
– stderr
I believe the answer here can help you: http://stackoverflow.com/questions/396748/ordering-by-the-order-of-values-in-a-sql-in-clause
– Rafael Withoeft