29 lines
867 B
Markdown
29 lines
867 B
Markdown
## MySQL踩坑记录
|
||
|
||
### 【1235】 This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME subquery’
|
||
|
||
+ ##### 说明:当前版本的 MySQL 不支持使用 LIMIT 子句的 IN/ALL/ANY/SOME 子查询
|
||
|
||
+ ##### 问题SQL
|
||
|
||
我想要查找凭证列表中的前十条记录
|
||
|
||
```mysql
|
||
SELECT * FROM voucher where id IN
|
||
(select DISTINCT(id) from voucher where is_deleted = 0 and DATE_FORMAT(v.bookkeeping_date,'%Y-%m') >= '2022-08' LIMIT 0,10)
|
||
```
|
||
|
||
+ ##### 原因
|
||
|
||
+ 原因在于子查询三层嵌套在 in或 not in 中使用了 limit
|
||
|
||
+ ##### 解决办法
|
||
|
||
将我们的SQL在进行嵌套一层,绕开limit子查询就可以了
|
||
|
||
```mysql
|
||
SELECT * from voucher where id IN
|
||
(select id from (select DISTINCT(id) from voucher where is_deleted = 0 and DATE_FORMAT(v.bookkeeping_date,'%Y-%m') >= '2022-08' LIMIT 0,10) vtable)
|
||
```
|
||
|
||
|