将所有行从一个表追加到另一个表

时间:2014-09-17 11:27:14

标签: sql postgresql

我正在使用PostgreSQL 9.3。假设我有两个sql-queries返回两个具有完全相同列名的表。例如:

(SELECT id, partner_registration_date
FROM partner) as tbl1

(SELECT id, partner_registration_date
FROM partner_statistic) as tbl2

我需要返回一个表格tbl,以便tbl_ROW_SET = tbl1_ROW_SET ∪ tbl2_ROW_SETtbl_COLUMN_SET = tbl1_COLUMN_SET = tbl2_COLUMN_SET

1 个答案:

答案 0 :(得分:0)

对于第一种情况,您可以尝试: -

SELECT id, partner_registration_date
FROM partner as tbl1
UNION ALL
SELECT id, partner_registration_date
FROM partner_statistic as tbl2;

第二,你可以尝试: -

SELECT DISTINCT id, partner_registration_date
FROM (SELECT id, partner_registration_date 
      FROM partner as tbl1
      UNION ALL
      SELECT id, partner_registration_date
      FROM partner_statistic as tbl2);

希望这可以帮到你。