检查两个表之间多列中的唯一值

check unique values in multiple colums between two tables

我正在尝试检查两个表中的多个列以查看表之间的任何行是否匹配。这就是我现在只有 1 列的内容:

        SELECT *
        FROM   {table1} 
        FULL OUTER JOIN {table2} 
        ON table1.colum1 = table2.colum1
        WHERE table1.colum1 IS NULL
        OR table2.colum1 IS NULL

这就是我尝试的 2 列:

        SELECT *
        FROM   {table1} 
        FULL OUTER JOIN {table2} 
        ON table1.colum1 = table2.colum1 and table1.colum2 = table2.colum2
        WHERE table1.colum1 IS NULL and table1.colum
        OR table2.colum1 IS NULL and table2.colum2 IS NULL

虽然这似乎有效。谁能帮我一下?

我在表 1 中的数据:

---------
| 1 | 1 |
---------
| 2 | 2 |
---------
| 2 | 3 |
---------

我在表 2 中的数据:

---------
| 1 | 1 |
---------
| 2 | 3 |
---------
| 2 | 4 |
---------

预期结果:

   t1      t2
-----------------
| 2 | 2 | 2 | 4 |
-----------------

提前致谢

惯用的基于集合的方法是使用 UNIONEXCEPT:

declare @t1 table (i1 int,i2 int)
insert into @t1(i1,i2) values
(1,1),
(2,2),
(2,3)

declare @t2 table (i1 int,i2 int)
insert into @t2(i1,i2) values
(1,1),
(2,3),
(2,4)

(select i1,i2 from @t1
except
select i1,i2 from @t2)
union all
(select i1,i2 from @t2
except
select i1,i2 from @t1)

结果:

i1          i2
----------- -----------
2           2
2           4

这应该可以解决问题:

SELECT coalesce(table1.col1, table2.col1) as col1
   , coalesce(table1.col2, table2.col2) as col2
FROM table1
FULL OUTER JOIN table2
    ON table1.col1 = table2.col1 and table1.col2 = table2.col2
WHERE (table1.col1 IS NULL and table1.col2 IS NULL)
    OR (table2.col1 IS NULL and table2.col2 IS NULL)