Ancien SQL pour une jointure complète - A concaténé avec B, ce qui exclut les lignes de B également en A (au milieu):
-- all rows in A with or without matching B
select a.x, a.y, a.z
from a
left join b
on a.x = b.x
and a.y = b.y
union all
-- all rows in B with no match in A to "exclude the middle"
select b.x, b.y, null as z
from b
where not exists (select null
from a
where b.x = a.x
and b.y = a.y)
ANSI style:
select coalesce(a.x, b.x) as x,
coalesce(a.y, b.y) as y,
a.z
from a
full outer join b
on a.x = b.x
and a.y = b.y
sont là pour la sécurité au coalesce; Je n'ai jamais vraiment eu de raison d'écrire une jointure externe complète dans le monde réel.
Si ce que vous voulez vraiment savoir si deux tables sont identiques, voici comment:
SELECT COUNT(*)
FROM (SELECT list_of_columns
FROM one_of_the_tables
MINUS
SELECT list_of_columns
FROM the_other_table
UNION ALL
SELECT list_of_columns
FROM the_other_table
MINUS
SELECT list_of_columns
FROM one_of_the_tables)
Si cela retourne un résultat non nul, alors il y a une différence. Cela ne vous dit pas dans quelle table il se trouve, mais c'est un début.
Exemple de données et de sortie prévue s'il vous plaît –