我有两张桌子:
表A
PK TBL_A_ID ITEM
0001 12345678 apple
0002 23456789 banana
表B
PK TBL_A_ID DESTINATION
0001 12345678 Boston
0002 23456789 London
0003 23456789 Rome
0004 12345678 Beijing
我想将表B DESTINATION更改为" Shanghai"如果ITEM是" banana"。
表B(预期结果)
PK TBL_A_ID DESTINATION
0001 12345678 Boston
0002 23456789 Shanghai
0003 23456789 Shanghai
0004 12345678 Beijing
可以用一行声明来完成吗?
答案 0 :(得分:1)
update table_b set destination='shanghai'
where tbl_a_id = (select tbl_a_id from table_a where item='banana')
答案 1 :(得分:0)
Update Table_B set Destination = 'Shanghai'
from Table_A a Join Table_B b on
a.TBL_A_ID = B.TBL_A_ID
where a.Item = 'Banana'