0

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?

oers
  • 18,436
  • 13
  • 66
  • 75

2 Answers2

1
update table_b set destination='shanghai' 
  where tbl_a_id = (select tbl_a_id from table_a where  item='banana')
oers
  • 18,436
  • 13
  • 66
  • 75
Bryan Pendleton
  • 16,128
  • 3
  • 32
  • 56
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'
oers
  • 18,436
  • 13
  • 66
  • 75
Deepak Sharma
  • 943
  • 6
  • 9