Jump to content


Defining Relationships In A Family

  • Please log in to reply
1 reply to this topic

#1 mschrank

  • Members
  • PipPip
  • Member
  • 12 posts

Posted 28 June 2006 - 06:45 PM

This is difficult. I wish people just kept to nuclear families where we could have simple relationships but it's more complicated now.

I've got the following tables (simplified of course):

name: family
columns: family_id, familyname

name: child
columns: firstname, lastname, child_id, family_id

name: parent
columns: firstname, lastname, parent_id, family_id

name: relationship
columns: parent_id, child_id, relationship

Now I know how to get the kids out that are not in relationship at all: select * from child, relationship where relationship.child_id <> child.child_id

But that's not what I want to do. I basically want to say, "find all the kids that are related to parent_id X" and then say "now show me all the kids that are not in that list"

#2 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 July 2006 - 02:13 AM

Shouldn't be a problem... simply issue a LEFT JOIN and search for WHERE child_id IS NULL.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users