如果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