Het lijkt erop dat je FULL OUTER JOIN
nodig hebt en gemeenschappelijk deel uitsluiten. Je kunt het simuleren met:
SELECT T1.col_name
FROM T1
LEFT JOIN T2
ON T1.col_name = T2.col_name
WHERE T2.col_name IS NULL
UNION
SELECT T2.col_name
FROM T2
LEFT JOIN T1
ON T1.col_name = T2.col_name
WHERE T1.col_name IS NULL;
╔══════════╗
║ col_name ║
╠══════════╣
║ C ║
║ D ║
║ E ║
║ F ║
║ G ║
╚══════════╝
Meer info:Visuele weergave van SQL-joins
SELECT <select_list>
FROM Table_A A
FULL OUTER JOIN Table_B B
ON A.Key = B.Key
WHERE A.Key IS NULL OR B.Key IS NULL
Helaas MySQL
ondersteunt geen FULL OUTER JOIN
dus ik gebruikte unie van 2 LEFT JOIN
.
Aanvulling
Je zou het gemakkelijk kunnen uitbreiden met extra kolommen.
SELECT 'T1' AS tab_name, T1.col_name, T1.col1, NULL AS col2
FROM T1
LEFT JOIN T2
ON T1.col_name= T2.col_name
WHERE T2.col_name IS NULL
UNION
SELECT 'T2' AS tab_name, T2.col_name, NULL, T2.col2
FROM T2
LEFT JOIN T1
ON T1.col_name= T2.col_name
WHERE T1.col_name IS NULL;
Uitgang:
╔══════════╦══════════╦══════╦═════════════════════╗
║ tab_name ║ col_name ║ col1 ║ col2 ║
╠══════════╬══════════╬══════╬═════════════════════╣
║ T1 ║ C ║ 3 ║ ║
║ T1 ║ D ║ 4 ║ ║
║ T2 ║ E ║ ║ 2016-01-03 00:00:00 ║
║ T2 ║ F ║ ║ 2016-01-02 00:00:00 ║
║ T2 ║ G ║ ║ 2016-01-01 00:00:00 ║
╚══════════╩══════════╩══════╩═════════════════════╝