Need help in updating table based on the values from another table using ORACLE SQL -
table (id,amt), table b (id, qty)
i need multiply a.amt b.qty , update values on table a. id cols equal in , b. query have created:
update set a.amt = (select a.amt * b.qty b join on a.id=b.id) exists (select a.amt * b.qty b join on a.id=b.id)
on execution returns error: single-row subquery returns more 1 row.
could me out on this.
for starters, re-using same table names without aliases on , on again hard through. may causing confusion. i'll try break down. start existing statement:
update set a.amt = (select a.amt * b.qty b join on a.id=b.id)
you setting a.amount = calculation on every matching a/b pair because not ensuring query related id of row updating! error coming from. instead:
update a1 set a1.amt = (select a2.amt * b.qty tot_amt b join a2 on a2.id=b.id a2.id = a1.id) -- link id of row updating!
ok, , can add in check matching b row update, in case can avoid rejoining unneccessary , use record working on
update a1 set a1.amt = (select a2.amt * b.qty tot_amt b join a2 on a2.id=b.id a2.id = a1.id) exists (select 1 b b2 b2.id=a1.id)
i have wonder if there isn't more need though far null checking or 0 checking work way want requirements.
Comments
Post a Comment