Reputation: 13
I've got two tables:
table A
PK TBL_A_ID ITEM
0001 12345678 apple
0002 23456789 banana
table B
PK TBL_A_ID DESTINATION
0001 12345678 Boston
0002 23456789 London
0003 23456789 Rome
0004 12345678 Beijing
I want to change table B DESTINATION to "Shanghai" if the ITEM is "banana".
table B (expected result)
PK TBL_A_ID DESTINATION
0001 12345678 Boston
0002 23456789 Shanghai
0003 23456789 Shanghai
0004 12345678 Beijing
Can it be done with one one line of statement?
Upvotes: 0
Views: 1200
Reputation: 16369
update table_b set destination='shanghai'
where tbl_a_id = (select tbl_a_id from table_a where item='banana')
Upvotes: 1
Reputation: 973
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'
Upvotes: 0