2013-09-24 58 views
0

我想通過通過唯一標識符進行連接來比較兩個不同表中的三個列。但是對於單個標識符,會有多個行將被返回。使用SQL中的單個標識符對多個行進行比較

例子:

Table A 

Identifier Flag1 Flag2 Flag3 

1   56 36 46 
1   89 65 33 
1   56 89 22 
1   11 89 65 

Table B 

Identifier Flag 1 Flag2 Flag3 

1   56 36 46 
1   89 65 33 
1   56 89 22 
1   10 89 65 

現在我想基於標識1這兩個表進行比較,可以請你幫我出,如果所有的列值匹配,我需要提前

更新flag.Thanks

回答

0

我想下面的代碼會有所幫助,下面 代碼將更新表A的標誌,其列中的值相同表b的記錄

update a 
set someflag = 1 
where exists 
(
select * from B 
where b.flag1 = a.flag1 
and b.flag2 = a.flag2 
and b.flag3 = a.flag3 
) 
相關問題