在一个表中合并3个表

时间:2013-07-21 18:19:35

标签: postgresql join

我在postgresql中有3个表(t1,t2,t3)。它们具有相同数量的列( 168 cols),具有相同的类型和总体 300k 行。

如何在一个表格中添加所有这些内容?

1 个答案:

答案 0 :(得分:2)

insert into t4
select * from t1
union all
select * from t2
union all
select * from t3

或者,如果要在选择期间创建表:

select * into t4 from t1
union all
select * from t2
union all
select * from t3;

SQL FIDDLE EXAMPLE