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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-04-11
  • 2021-09-21
  • 2022-01-11
  • 2021-09-27
  • 2021-04-01
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-14
  • 2021-11-17
  • 2022-02-19
  • 2021-06-07
  • 2021-11-14
相关资源
相似解决方案