mysql中limit和order by同时使用时问题的解决

mysql中使用ORDER BY 之后再用Limit没有效果,使用Limit之后再用ORDER BY报错:ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'limit
 0,10) order by id desc' at line 1

解决方法:

select * from (select * from p_picture where limit 0,10) order by id desc;

 这也写法是不对的,正确的写法如下:

select * from (select * from p_picture order by id desc) id limit 0,10;

 

猜你喜欢

转载自oaksun.iteye.com/blog/1830058