FULL OUTER JOIN
が必要なようです 共通部分を除外します。次のコマンドでシミュレートできます:
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 ║
╚══════════╝
詳細:SQL結合の視覚的表現
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
残念ながら、MySQL
FULL OUTER JOIN
はサポートしていません そこで、2つのLEFT JOIN
の和集合を使用しました 。
補遺
追加の列で簡単に拡張できます。
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;
出力:
╔══════════╦══════════╦══════╦═════════════════════╗
║ 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 ║
╚══════════╩══════════╩══════╩═════════════════════╝