问题:MySQL doesn't yet support 'LIMIT & IN/ALL/AN Y/SOME subquery

来源:互联网 发布:怎么开启内网端口 编辑:程序博客网 时间:2024/06/05 02:00

MySQL中子查询是不能使用LIMIT 会报错: “This version of MySQL doesn’t yet support ‘LIMIT & IN/ALL/ANY/SOME subquery’ ” 

SQL语句应该这样写(红色子所示),即在包装一层,避开limit关键字

String sql = "select p.id,p.product_name,p.description,p.add_time," +
"p.fixed_price,p.dang_price,p. product_pic,b.author,b.publishing," +
"b.publish_time,b.word_number,b.which_edtion,b.total_page," +
"b.isbn from d_d_book b inner join d_d_product p on b.id = p.id " +
"where p.id in (select t.product_id from (select product_id  from d_d_item group by product_id " +
"order by count(product_id) limit 3) as t)";

不应该

String sql = "select p.id,p.product_name,p.description,p.add_time," +
"p.fixed_price,p.dang_price,p. product_pic,b.author,b.publishing," +
"b.publish_time,b.word_number,b.which_edtion,b.total_page," +
"b.isbn from d_d_book b inner join d_d_product p on b.id = p.id " +
"where p.id in (select product_id  from d_d_item group by product_id " +
"order by count(product_id) limit 3)";

原创粉丝点击