I'm using PostgreSQL 9.3. Suppose I have two sql-queries which return two tables with completely the same column names. For instance:
(SELECT id, partner_registration_date
FROM partner) as tbl1
and
(SELECT id, partner_registration_date
FROM partner_statistic) as tbl2
I need to return a table tbl
such that tbl_ROW_SET = tbl1_ROW_SET ∪ tbl2_ROW_SET
and tbl_COLUMN_SET = tbl1_COLUMN_SET = tbl2_COLUMN_SET
For first case you can simply try:-
SELECT id, partner_registration_date
FROM partner as tbl1
UNION ALL
SELECT id, partner_registration_date
FROM partner_statistic as tbl2;
And for second you can try with:-
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);
Hopefully this helps you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.