Solved

getting parent key

Posted on 2014-01-21
4
160 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
[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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

705 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