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

mysql在子查询in中用了limit,然后报错:

[SQL] 
select distinct(p.id) poetryId,content poetryDesc,author poetryAnthor,l.backImg labelImg,p.fullContent flag,archaics,moods,scenes,hots,works,2 collectionType,l.archaicsImg,p.worksName from dd_poetry p join dd_label l on l.id = p.archaics  where 1=1 
and p.id in(
	 select id from dd_poetry order by rand()  limit 100 
)


[Err] 1235 - This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

in (select id from table limit 100)的时候报错~~~~


解决办法:

在limit的外层在套一层:in (select id from (select id from table limit 100) as t)的时候报错~~~~

select distinct(p.id) poetryId,content poetryDesc,author poetryAnthor,l.backImg labelImg,p.fullContent flag,archaics,moods,scenes,hots,works,2 collectionType,l.archaicsImg,p.worksName from dd_poetry p join dd_label l on l.id = p.archaics  where 1=1 
and p.id in(
	select t.id from (select id from dd_poetry order by rand()  limit 100) as t
)

这里用了order by rand()耗性能的关键字,但是如果使用主键id来随机的话,就不会影响性能~


先随机100条再来查询

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值