解决 mysql in 查询排序问题

版权声明:本文为博主原创文章,未经博主允许不得转载。https://blog.csdn.net/chenyao1994 https://blog.csdn.net/chenyao1994/article/details/83342725
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') 

猜你喜欢

转载自blog.csdn.net/chenyao1994/article/details/83342725