Solved

getting parent key

Posted on 2014-01-21
4
156 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 73

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 73

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 73

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
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.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

776 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