Først skal du indlæse tabellerne i to separate skemaer i den samme database.
CREATE SCHEMA db1;
CREATE TABLE db1.table1 (id INT PRIMARY KEY, value VARCHAR(10));
-- load the contents of Table1 @ Database1 into db1.table1
CREATE SCHEMA db2;
CREATE TABLE db2.table1 (id INT PRIMARY KEY, value VARCHAR(10));
-- load the contents of Table1 @ Database2 into db2.table1
Derefter kan du slå de to sammen ved at prioritere db2 over db1.
SELECT
DISTINCT ON (id)
id,
value
FROM (
SELECT
*,
1 AS db
FROM
db1.table1
UNION
SELECT
*,
2 AS db
FROM
db2.table1) AS mix
ORDER BY
id,
db DESC;