Joshua Chung
Joshua Chung

Reputation: 13

Update table_A value based on table_B in Derby

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

Answers (2)

Bryan Pendleton
Bryan Pendleton

Reputation: 16369

update table_b set destination='shanghai' 
  where tbl_a_id = (select tbl_a_id from table_a where  item='banana')

Upvotes: 1

Deepak Sharma
Deepak Sharma

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

Related Questions