?
Solved

How to update join.view when not using primary key

Posted on 2003-02-27
2
Medium Priority
?
460 Views
Last Modified: 2009-07-29
I want to execute the following query:

UPDATE A SET A.VALUE = A.VALUE + B.VALUE WHERE A.NOT_PRIMARY_KEY = B.NOT_PRIMARY_KEY;


For every row in a, there are multiple rows in b. I want to update every row in a that matches the criteria. How can I do this?

Example data:

Table A
NotPK   Value
1       1
2       2
3       3
3       4

Table B
NotPK   Value
1       1
2       2
2       3
3       3

Results:
Table A
NotPK   Value
1       2 (1+1)
2       7 (2+2+3)
3       6 (3+3)
3       7 (3+4)
0
Comment
Question by:covington
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 8

Accepted Solution

by:
Danielzt earned 400 total points
ID: 8036581

if you are in oracle, try this:

UPDATE A SET A.VALUE = A.VALUE + (select sum(B.VALUE)
 from B WHERE A.NOT_PRIMARY_KEY = B.NOT_PRIMARY_KEY );



0
 
LVL 3

Author Comment

by:covington
ID: 8036886
Perfect, thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that useā€¦
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
Via a live example, show how to take different types of Oracle backups using RMAN.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question