HuyPV
Thursday, August 18, 2011
SELECT * FROM tbl_name WHERE column_a IN ( val1, val2, val3 )
ORDER BY FIELD(column_a, val1, val2, val3);
SELECT id, title FROM article WHERE id IN (20, 10, 2010)
ORDER BY FIELD(id, 20, 10, 2010);
20 - Title 20
10 - Title 10
2010 - Title 2010
Want to see complex SQL?
SELECT * FROM tbl_name WHERE column_a IN ( val1, val2, val3 )
ORDER BY column_a = val1 DESC, column_a = val2 DESC, column_a = val3 DESC;
Title:
mysql order by where in
Description:
SELECT * FROM tbl_name WHERE column_a IN ( val1, val2, val3 ) ORDER BY FIELD(column_a, val1, val2, val3); SELECT id, title FROM article ...
...
Rating:
4