Julius Benn Sabeniano
Julius Benn Sabeniano

Reputation: 27

How to update table A values from table B values?

I have a table (Table A) from the db2 where columns(Date, Part#, tool#, power) need to be updated based from the Table B.

Table A
Date   part# tool# power
04/09   12    1     500
04/10   13    2     600
04/11   14    1     700

Table B 
Date   part# tool# power speed wheel
04/09   12    1    500    128    2
04/10   13    2    600    129    2
04/11   14    1    700    130    4
04/12   15    3    800    130    3
04/13   16    1    500    140    3
04/14   17    3    500    150    4

So the final result in Table A should be like below

Table A
Date  part# tool# power
04/09 12     1     500
04/10 13     2     600
04/11 14     1     700
04/12 15     3     800
04/13 16     1     500
04/14 17     3     500

How will i do it using db2 sql?

Upvotes: 0

Views: 47

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270773

Are you looking for this?

insert into a (date, part#, tool#, power)
    select b.date, b.part#, b.tool#, b.power
    from b
    where not exists (select 1 from a where b.date = a.date);

Upvotes: 0

Related Questions