sql中order子句和limit子句的順序問題

早上修改代碼,增長排序功能,因而我就在以前sql的最後面增長了order by。發現sql出錯:sql

SELECT item_id,title,price,pic,last_modify_time,detail,sellor,sellor_addr 
FROM item 
WHERE isnew=0
LIMIT 10 OFFSET 0 
ORDER BY id DESC

試驗發現當Limit子句和Order子句同時存在時候,Order子句必需要在前面,邏輯上也很好理解,排序完成後,再進行截取所須要的部分。code

SELECT item_id,title,price,pic,last_modify_time,detail,sellor,sellor_addr 
FROM item 
WHERE isnew=0
ORDER BY id DESC
LIMIT 10 OFFSET 0
相關文章
相關標籤/搜索