怎么把两张表的数据插入到一张表中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎么把两张表的数据插入到一张表中相关的知识,希望对你有一定的参考价值。
参考技术A 你的意思是有三个表table_1,table_2,table_3;
其中把table_1和table_2的值插入到table_3对吧?
但是你没有说明是怎么个插法
下面分两种情况:
1.table_1和table_2有主键可以关联,比如说table_1有a,b,c,d四个字段table_2有a,s,w,e四个字段,你是要根据a字段关联得到
a,b,c,d,s,w,e这样的table_3
insert
into
table_3
select
t1.*,t2.s,t2.w,t2.e
from
table_1
t1,table_2
t2
where
t1.a=t2.a;
2.三个表的表结构是一样的,你是要把table_1,table_2数据汇总到table_3
分开插入两次就可以了:
insert
into
table_3
select
*
from
table_1
where...
insert
into
table_3
select
*
from
table_2
where
...
以上是关于怎么把两张表的数据插入到一张表中的主要内容,如果未能解决你的问题,请参考以下文章
oracle的数据库中怎么将一张表中数据插入另一张表,两张表都存在