SQL查询执行更新查询时的条件

时间:2014-01-09 11:46:53

标签: sql ms-access-2010

团队,我有三个表Table1,Table2和TableComment。如果Table2数据与TableComment的三列数据匹配,我只想更新Table2到Table1的数据。在下面的示例中,Table2中的第一行应在Table1中更新,而第二行不应更新。

表1

TID Category    Sub Category    Code
123456  1. AAAAA    1.1 First   FF1
234567          
345678          
124123          
123413          
635464      

表2

TID Category    Sub Category    Code
123456  1. AAAAA    1.1 First   FF1
234567  1. AAAAA    2.1 First   FS1

表评论

Category    Sub Category    Code
1. AAAAA    1.1 First   FF1
1. AAAAA    1.1 First   FF2
1. AAAAA    1.1 First   FF3
1. AAAAA    1.2 Second  FS1
1. AAAAA    1.2 Second  FS2
1. AAAAA    1.2 Second  FS3
1. AAAAA    1.3 Third   FT1
1. AAAAA    1.3 Third   FT2
1. AAAAA    1.3 Third   FT3
2. BBBBB    2.1 First   SF1
2. BBBBB    2.1 First   SF2
2. BBBBB    2.1 First   SF3
2. BBBBB    2.2 Second  SS1
2. BBBBB    2.2 Second  SS2
2. BBBBB    2.2 Second  SS3
2. BBBBB    2.3 Third   ST1
2. BBBBB    2.3 Third   ST2
2. BBBBB    2.3 Third   ST3

示例代码

UPDATE (Table1 INNER JOIN Table2 ON Table1.TID = Table2.TID) INNER JOIN TableComment 
ON Table2.Category = TableComment.Category and 
Table2.[Sub Category] = TableComment.[Sub Category] and
Table2.[Code] = TableComment.[Code]
SET Table1.Category = Table2.Category and 
Table1.[Sub Category] = Table2.[Sub Category] and
Table1.[Code] = Table2.[Code]

0 个答案:

没有答案