Solved

getting parent key

Posted on 2014-01-21
4
158 Views
Last Modified: 2014-01-24
Hi,
My Input is like below

Parent_code child_code CHILD_SK PARENT_SK
               00.1        1
ABC.20         ABC         2       null
ABC.20         CDE.20      3       null
ABC.20         EFG.20      4       null
BDE.20         ABC.20      5       null


i want to update parent_sk as below based upon join from parent_code with child_code:

so output should be like below


Parent_code child_code CHILD_SK PARENT_SK
               00.1        1       null
ABC.20         ABC         2       5
ABC.20         CDE.20      3       5
ABC.20         EFG.20      4       5
BDE.20         ABC.20      5       5

Open in new window


Thanks
0
Comment
Question by:sam2929
  • 3
4 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 39798879
I'm afraid I don't understand the join conditions

why is the last row updated to 5?


getting the other rows is easy

update yourtable a SET parent_sk = (select child_sk from yourtable  b
where a.parent_code = b.child_code
)
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 39798888
I probably need a rule for the first row too.  The update above will set it to NULL, but sort of incidentally.  If there is something more explicit, please explain.
0
 

Author Comment

by:sam2929
ID: 39798889
My bad it should be null
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 39798904
"it"  ?

Does "it" refer to the first row or the last row?  

If both,  then the update above should do it for you.

If not, can you be more specific? And since there were 2, which ever one you didn't mean, can you explain the rule for that one too?
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

730 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