db2 - SQL : Compare table data and update the correct value in tables -


i have below data discrepancy in few of tables needs corrected using update queries in sql

the master table( take table a) table contains 2 primary key value same product below,

------------------ prrfnbr|prnbr -------|-------- xxxx   |123 yyyy   |123 ---------------- 

and these reference keys used in 2 tables below ,

table b:

---------------------- suprfnbr |susprnbr --------------------- xxxx     |   234 ------------------- 

table c:

------------------- seprfnbr |  sesuprnbr ------------------- yyyy     | 435 -------------------- 

now need compare these 3 tables , update seprfnbr in table c reference key available in table b (suprfnbr ) ( reference key xxxx needs updated in table c if same prnbr having 2 primary key values in table a)

your logic - far understood - not need reference table different suprfnbr & seprfnbr qualify update

update c set seprfnbr = (select suprfnbr b b.suprnbr = c.seprnbr) 

if (undescribed) reason lookup table necessary extended like

update c set seprfnbr = (select suprfnbr b                            b.suprnbr = c.seprnbr)                              , (select count(*)                                    b.suprnbr = a.prnbr) > 1)" 

you may vary solution depending on other side constraints may have. ment solution idea.


Comments

Popular posts from this blog

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -