解决 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') 

 

posted @ 2015-01-22 18:21  飞凡123  阅读(1938)  评论(0编辑  收藏  举报