MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Parent-child relationships

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
ofer71
Intermediate


Joined: 12 Feb 2003
Posts: 358
Topics: 4
Location: Israel

PostPosted: Wed Jun 30, 2004 7:01 am    Post subject: Parent-child relationships Reply with quote

Hi all

Please help with the following issue:

I have 2 tables, parent and child - like the following example:
Code:

Parent:

CLIENT_ID     CLIENT_NAME
------------  ----------------------
1111111       AAAAAAAA
2222222       BBBBBBBBB


Child:

CLIENT_ID    ADDRESS
------------ ---------------
1111111      ADDRESS1A
1111111      ADDRESS1B
1111111      ADDRESS1C
2222222      ADDRESS2A
2222222      ADDRESS2B
2222222      ADDRESS2C


- Each record in the parent table connected to exactly 3 records in the child table.

The expected output is like this:
Code:

CLIENT_ID   CLIENT_NAME     ADDRESS(A)    ADDRESS(B)     ADDRESS(C)
----------  --------------  ------------- -------------- -------------------
1111111     AAAAAAAA        ADDRESS1A     ADDRESS1B      ADDRESS1C
2222222     BBBBBBBB        ADDRESS2A     ADDRESS2B      ADDRESS2C


That is - a "flat" view of the 1 parent record & 3 child records.

Can this be achived using single-simple SQL query ?

Thanks in advance -

O.
________
Subaru Rex history


Last edited by ofer71 on Sat Feb 05, 2011 11:17 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Manas Biswal
Intermediate


Joined: 29 Nov 2002
Posts: 382
Topics: 27
Location: Chennai, India

PostPosted: Wed Jun 30, 2004 8:29 am    Post subject: Reply with quote

ofer71,

I would have first of all changed the structure of my child table....Very Happy

Regards,
Manas
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
ofer71
Intermediate


Joined: 12 Feb 2003
Posts: 358
Topics: 4
Location: Israel

PostPosted: Wed Jun 30, 2004 8:34 am    Post subject: Reply with quote

Sorry, can't be done. This is a client's table that not going to be changed.
________
Honda XR600 history


Last edited by ofer71 on Sat Feb 05, 2011 11:17 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
vini
Intermediate


Joined: 12 Jan 2004
Posts: 240
Topics: 48
Location: Maryland

PostPosted: Wed Jun 30, 2004 2:59 pm    Post subject: Reply with quote

ofer71, Are there any other columns in child table. If yes, what are they ? Is it oracle /db2 ?

Am asking based on the assumption that the values ADDRESS1A ,ADDRESS1B , ADDRESS1C you have listed for ADDRESS are not to be treated literally and are just a way of representation.
Back to top
View user's profile Send private message
ofer71
Intermediate


Joined: 12 Feb 2003
Posts: 358
Topics: 4
Location: Israel

PostPosted: Wed Jun 30, 2004 3:04 pm    Post subject: Reply with quote

Hi

There are other columns in the child table. One of them is occurence.

A little explanation: The parent & child tables used to be a single file in a hierarchical database. The child table derived from a multi-occurence field in the old file, and is logically connected by CLIENT_ID to its original record.

And no, it's not Oracle.
________
RZ350


Last edited by ofer71 on Sat Feb 05, 2011 11:17 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
vini
Intermediate


Joined: 12 Jan 2004
Posts: 240
Topics: 48
Location: Maryland

PostPosted: Wed Jun 30, 2004 3:14 pm    Post subject: Reply with quote

ofer71, what exactly does occurence contain .. is it like 1,2,3 ?
Back to top
View user's profile Send private message
ofer71
Intermediate


Joined: 12 Feb 2003
Posts: 358
Topics: 4
Location: Israel

PostPosted: Wed Jun 30, 2004 3:15 pm    Post subject: Reply with quote

Yes.
________
cheap glass bongs


Last edited by ofer71 on Sat Feb 05, 2011 11:17 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
vini
Intermediate


Joined: 12 Jan 2004
Posts: 240
Topics: 48
Location: Maryland

PostPosted: Wed Jun 30, 2004 3:21 pm    Post subject: Reply with quote

Try this ..

Code:

Select P.CLIENT_ID
      ,P.CLIENT_NAME
      ,A.ADDRESS
      ,B.ADDRESS
      ,C.ADDRESS
  From Parent P
      ,Child A
      ,Child B
      ,Child C
  Where P.CLIENT_ID = A.CLIENT_ID
   And A.OCCURENCE = 1
   And P.CLIENT_ID = B.CLIENT_ID
   And B.OCCURENCE = 2
   And P.CLIENT_ID = C.CLIENT_ID
   And C.OCCURENCE = 3
  ;
Back to top
View user's profile Send private message
Manas Biswal
Intermediate


Joined: 29 Nov 2002
Posts: 382
Topics: 27
Location: Chennai, India

PostPosted: Thu Jul 01, 2004 9:36 am    Post subject: Reply with quote

ofer71,

What is the primary key of the CHILD table. This is DB2 or Oracle?

Regards,
Manas
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
ofer71
Intermediate


Joined: 12 Feb 2003
Posts: 358
Topics: 4
Location: Israel

PostPosted: Thu Jul 01, 2004 9:54 am    Post subject: Reply with quote

My primary key is CLIENT_ID + OCCURENCE.

And again: DB2.
________
buy volcano vaporizer


Last edited by ofer71 on Sat Feb 05, 2011 11:18 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Thu Jul 01, 2004 10:11 am    Post subject: Reply with quote

ofer71,

Did you try Vini's suggestion. It sure works and gives you the desired results.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ofer71
Intermediate


Joined: 12 Feb 2003
Posts: 358
Topics: 4
Location: Israel

PostPosted: Thu Jul 01, 2004 10:22 am    Post subject: Reply with quote

Yes, it did.

Thanks for all the help.

O.
________
roor bong


Last edited by ofer71 on Sat Feb 05, 2011 11:18 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Anand_R
Intermediate


Joined: 24 Dec 2002
Posts: 189
Topics: 60

PostPosted: Fri Jul 02, 2004 3:57 am    Post subject: Reply with quote

Hi Vini,

I didn't get the concept of 'OCCURENCE'. Is it the column name in the table given by OFER or the part of SQL command. Can you please give me the link for detailed explanation for OCCURENCE. I was trying to find it in SQL refence. but no luck..

Thanks
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Fri Jul 02, 2004 4:45 am    Post subject: Reply with quote

Anand_r,

Did you read the following posts by ofer71?

Quote:

There are other columns in the child table. One of them is occurence.


Quote:

My primary key is CLIENT_ID + OCCURENCE.


kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group