Solved

getting parent key

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Generate HTML charts from SQL 4 51
Pl/SQL Query 31 62
Wrap Oraccle SQL*Plus executable Command 4 36
automatic email alert 1 21
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…
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.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now