?
Solved

getting parent key

Posted on 2014-01-21
4
Medium Priority
?
176 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 2000 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Suggested Courses

807 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