Det verkar som att du behöver FULL OUTER JOIN
och utesluta gemensamma delar. Du kan simulera det med:
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 ║
╚══════════╝
Mer information:Visuell representation av SQL-kopplingar
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
Tyvärr MySQL
stöder inte FULL OUTER JOIN
så jag använde union av 2 LEFT JOIN
.
Tillägg
Du kan enkelt utöka den med ytterligare kolumner.
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;
Utdata:
╔══════════╦══════════╦══════╦═════════════════════╗
║ 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 ║
╚══════════╩══════════╩══════╩═════════════════════╝