想实现:在主表分页的同时,把子表的数据也查出来:
本人写的会报错:
本人写的会报错:
select * from order_info i left join order_detail d on i.id = d.order_id where i.id in ( select id from order_info order by id desc limit 0,5 ); Error Code: 1235. This version of MySQL doesn"t yet support "LIMIT & IN/ALL/ANY/SOME subquery
表结构:
CREATE TABLE `order_info` ( `id` int(11) NOT NULL, `date` datetime DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `order_detail` ( `id` int(11) NOT NULL, `order_id` int(11) DEFAULT NULL, `fee` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; INSERT INTO `order_info` VALUES (1,"2016-09-28 10:10:10"),(2,"2016-09-28 10:10:11"),(3,"2016-09-28 10:10:12"),(4,"2016-09-28 10:10:13"),(5,"2016-09-28 10:10:14"),(6,"2016-09-28 10:10:15"),(7,"2016-09-28 10:10:16"),(8,"2016-09-28 10:10:17"),(9,"2016-09-28 10:10:18"),(10,"2016-09-28 10:10:19"),(11,"2016-09-28 10:10:20"); INSERT INTO `order_detail` VALUES (1,1,20),(2,1,30),(3,1,50),(4,2,10),(5,2,20),(6,3,20),(7,4,10),(8,4,30),(9,5,20),(10,6,10),(11,7,20),(12,8,40),(13,9,80),(14,10,10),(15,10,50),(16,11,20);
解决方案
100
这样的语句是不能正确执行的。
select * from table where id in (select id from table limit 10);
但是,只要你再来一层就行。如:
select * from table where id in (select t.id from (select * from table limit 10)as t)
select * from table where id in (select id from table limit 10);
但是,只要你再来一层就行。如:
select * from table where id in (select t.id from (select * from table limit 10)as t)