[Err] 1235 - This version of MysqL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'
原sql语句:
SELECT id,friend_id,sender_id,obj_key,comment_id,content,ctime from msg where id in (SELECT MAX(id) as id FROM msg WHERE user_id = 312 and status !=3 GROUP BY obj_key,comment_id ORDER BY id DESC LIMIT 10)
解决办法:
比如这样的语句是不能正确执行的。
select * from table where id in (select id from table limit 12);
第一种方法:只要你再加一层就行。如:
select * from table where id in (select t.id from (select * from table limit 12) as t)
第二种方法:
select * from (select id from table limit 12) as t;
第三种方法:使用inner join .... on ....
select t.id from table as t inner join (select id from table limit 12) as t2 on t.id=t2.id
建议使用inner join,因为通常db引擎会将where 解析为join
参考:http://blog.chinaunix.net/uid-22414998-id-2945656.html