开发者

Selecting records from subquery on multiple columns

I'd like to do something like this:

Suppose I have two tables, myTable1 and myTable2. Suppose both of these tables have columns myColumn1 and开发者_C百科 myColumn2.

update
   myTable1
set
   myTable1.myFlagColumn = 1
where
    myTable1.myColumn1, myTable1.myColumn2
       in
          (select myTable2.myColumn1, myTable2.myColumn2 from myTable2)

Essentially, I want to change a value in myTable1 if there are any rows where the two columns in myTable1 and myTable2 match.

Is this possible?


Yes, but you will use an EXISTS clause:

 update
    myTable1
 set
    myTable1.myFlagColumn = 1
 where
     EXISTS
     (select * FROM myTable2 WHERE myTable2.myColumn1 = myTable1.myColumn1 
     AND myTable2.myColumn2 = myTable1.myColumn2)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜