INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to create Master/Detail/Detail/Detail?

How to create Master/Detail/Detail/Detail?

(OP)

I use Interbase 6 SQLServer in conjunction with Delphi 6 Enterprise.

I have a FATHER (Master), CHILD (Detail), GCHILD (Detail), GGCHILD (Detail) relationship.

I find (Example 1) below works perfectly. But Examples 2 and 3 do not.

Can someone please tell me what I am doing wrong?

Example 2 provides any and all GRANDCHILDREN who have a join to a CHILD and FATHER.
Example 3 provides any and all GREATGRANDCHILDREN who have a join to a GRANDCHILD, CHILD
and FATHER.

which is (of course) ALL of them and is not what I want.

What I want is:
In Example 2 when POINTING to (say) FATHER 2 and (his) CHILD 3 at any given moment I want
ONLY the GRANDCHILDREN of FATHER 2 and CHILD 3.
Equally When POINTING to (say) FATHER 3, (his) CHILD 2 and GRANDCHILD 1 at a given moment
I want to see ONLY the GREAT-GRANDCHILDREN of FATHER 3, CHILD 2 and GRANDCHILD 1.

EXAMPLE 1

select *
from CHILD t1, FATHER t2
where t1.P_NO = t2.P_NO

EXAMPLE 2

select *
from GCHILD t1, CHILD t2, FATHER t3
where (t1.P_NO = t3.P_NO) AND (t1.C_NO = t2.C_NO)

EXAMPLE 3

select *
from GGCHILD t1, GCHILD t2, CHILD t3, FATHER t4
where (t1.P_NO = t4.P_NO) AND (t1.C_NO = t2.C_NO) AND (t1.GC_NO = t3.GC_NO)

Thanks in advance

RE: How to create Master/Detail/Detail/Detail?

I think your doing some logical misstake or have wrong info in the tables.

An alternative way to do it is using selfjoin and one table:

Table PERSON
ID        number
FATHERID  number
MOTHERID  number
NAME      char(40)

EXAMPLE 1 - getting father and child

select f.id, f.name, c.id, c.name
from   person f, person c
where  c.fatherid = f.id;

EXAMPLE 2 - getting father, child and grandchild

select f.id, f.name, c.id, c.name, gc.id, gc.name
from   person f, person c, person gc
where  c.fatherid = f.id
and    gc.fatherid = c.id

EXAMPLE 3 - getting father, child, grandchild and grand grand child

select f.id, f.name, c.id, c.name,
       gc.id, gc.name, ggc.id, ggc.name
from   person f, person c, person gc, person ggc
where  c.fatherid = f.id
and    gc.fatherid = c.id
and    ggc.fatherid = gc.id

RE: How to create Master/Detail/Detail/Detail?

(OP)
Case closed

Thanks very much for you time and trouble - but I think you are missing some vital points.  Which I have explained in
my Thread102-272955.  Which also provides a solution - which I don't consider to be very elegent. I was hoping for something better.  But it works. Except for a peculiarity just described there - which I have yet to resolve.

Terry

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close