MySQL 子查询中不支持 LIMIT 的问题

本文介绍了一种在MySQL中解决LIMIT与IN/ALL/ANY/SOME子查询不兼容问题的方法。通过在子查询中增加额外一层查询来绕过限制,确保了查询能够正确执行。

今天要实现一个功能,于是构造如下SQL语句:

select * from tx_dailylabel where dl_type='3' and d_id in  (select train_id from tx_training where train_isdelete=0 and train_isdraft=0 and train_ischeck=0 limit 0,10) ;

执行该语句,MySQL提示错误:

 This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

 

无奈Google之,发现解决办法就是再子查询中再嵌套一层查询:

select * from tx_dailylabel where dl_type='3' and d_id in (select train_id from (select train_id from tx_training where train_isdelete=0 and train_isdraft=0 and train_ischeck=0 limit 0,10) as table1)

一测试居然可以,不由得感叹,人民群众真是智慧的群体啊,于是记录于此。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值