日期:2014-05-16  浏览次数:20691 次

mysql 查询主键排序问题
id是主键,查询就会默认的按主键排序,可不可以去掉这个排序,就按照我的 4 3 1 排序出来
select * from article where id = 4 or id = 3 or id = 1

------解决方案--------------------
select * from article order by find_in_set(id,'4,3,1')
or
select * from article order by if(id = 4,1,if(id = 3,2,if(id = 1,3,4)))
------解决方案--------------------
select * 
from article 
where id = 4 or id = 3 or id = 1
order by find_in_set(id,'4,3,1')