2019-02-21
阅读量:
2797
mysql子查询无法重复使用临时表的解决方法?
问题描述:
当我们在使用mysql进行数据查取的时候,往往会涉及临时表的功能,但是当一个query语句中,如果使用了多个临时表,会报错1146,对于这个问题应该如何解决?
解决思路:
- 可以采取创建多个临时表的思路予以解决,也就是把子查询结果封装为新的临时表(create temporary table xxx as (子查询))
#drop temporary table tem;
create temporary table tem(
OrderID int,
Userid int,
primary key(OrderID,Userid)
);
insert into tem
select o.OrderID,o.UserID from orderinfo o;
select * from tem limit 3;
select * from tem_new limit 3;
create temporary table tem_new as(select OrderID from new_tem order by OrderID limit 20,3) ;
select *
from tem
inner join tem_new using (OrderID);#on tem.OrderID=tem_new.OrderID






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论