-1

我有 2 张表 temp1 和 temp2。我在 temp1 中有 5 列(a、b、c、d、e),在 temp2 中有 5 列(a、b、c、d、e)

我想要简单的加入

a) temp1 中而不是 temp2 中的值 b) temp2 中而不是 temp1 中的值

4

3 回答 3

0

如果要比较两个表上的所有记录,则需要JOIN对所有列进行比较。如果您可以做除 a 之外的其他事情JOIN,那么我建议EXCEPT

 a):

SELECT *
FROM temp1
EXCEPT
SELECT *
FROM temp2

 b):

SELECT *
FROM temp2
EXCEPT
SELECT *
FROM temp1
于 2012-05-15T16:01:04.130 回答
0

试试这个..它可能对你有用:

select COLUMN1,COLUMN2,COLUMN3 from TABLE1 where COLUMN1 not in (select COLUMN1  from TABLE2);
于 2012-05-15T16:01:48.857 回答
0

那么取决于你的匹配标准是什么。这假设 A 是您可以使用的唯一 id,如果不添加更多到 on 子句。

Select 'In Temp1 but not temp2',temp1.*
From Temp1 
Outer Join Temp2 On temp1.A = temp2.A Where temp2.A is null
Union
Select 'In Temp2 but not temp1',temp2.*
From Temp2 
Outer Join Temp1 On temp2.A = temp1.A Where temp1.A is null
于 2012-05-15T16:10:57.827 回答