解决 mysql in 查询排序问题

select id,title from za_item where -- 
id in (1003,1000)

返回的结果第一条是对应id是1000,第二条是1003。

如果我们想让结果和in里面的排序一致,可以这么做。

select id,title from za_item where
id in (1003,1000)
order by field(id,1003,1000);

或者

select id,title from za_item where
id in (1003,1000)
order by find_in_set(id,'1003 ,1000') 
原文地址:https://www.cnblogs.com/mafeifan/p/4242414.html