mysql子查詢不支持limit問題解決


如果sql語句中的子查詢包含limit

例如:

select * from table where id in (select id from table limit 3)

會報錯:

This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME

解決辦法:

  1、加一層子查詢

  例如:select * from table where id in (select t.id from (select * from table limit 3)as t)

  2、把限制條件放到from而非where子句中,就不必出現嵌套再嵌套。

  例如:select * from (select id from table limit 3) as foo

注意:其實as foo特別重要,如果不寫成from () as xxx的形式,即不給from后的select語句構成表名,那么最后系統仍會報錯。

————————————————
版權聲明:本文為CSDN博主「zhuocr」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/zhuocr/article/details/61192418

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM