select * from table_name where id in ()
或者
select * from table_name where find_in_set()
的时候,MySQL会自动按主键自增排序,要是按给定的顺序来取,如何实现呢?
- 1、使
in
按顺序查出来
select ID from IndexData where Type=2 and RelateID in(2,4,1,3) order by FIND_IN_SET(RelateID,'2,4,1,3');
- 2、使
find_in_set
按顺序查出来
select ID from IndexData where Type=2 and FIND_IN_SET(RelateID,'2,4,1,3') order by FIND_IN_SET(RelateID,'2,4,1,3');
猜你喜欢:
暂无回复。