Results 1 to 7 of 7
  1. #1
    HPG is offline Novice
    Windows Vista Access 2000
    Join Date
    Nov 2011
    Posts
    1

    Relate rows in a single table

    I am in the following situation: I have made a table containing information about people I know. I am trying to find a way to keep track of marriages. Marriages are relations between people in the same table. So far I have made a table called marriages. This table contains two columns (and a key). These two columns each have a relation to the same column in the other table. PersonID is foreign key in man, and also in whife. I invented this way myself, and I am uncertain about it. But in my mind it should work fine. The problem I have is that I am unable to get the information back out. Do I use SELECT? Or does this way work at all?

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    I'd suggest searching for info on these topics, just to get a view of what's involved

    Representing Hierarchies in database tables
    Genealogy database structure
    Modeling hierarchical data
    gedcom

    This is not a trivial subject. I'd suggest getting a look at a number of options.

  3. #3
    Amicron's Avatar
    Amicron is offline Access Guru
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Amherst, New York (near Buffalo)
    Posts
    31
    If your primary table looks like this:

    PersonT
    PersonID
    FirstName
    LastName
    (etc.)

    I would create a second table to hold the marriages, as you've done:

    MarriageT
    MarriageID
    Spouse1
    Spouse2

    Spouse1 and 2 are FOREIGN KEY fields pointing to a PersonID.

    Now your data would look like this:

    PersonT:
    1, Joe, Smith
    2, Bill, Jones
    3, Amy, Smith
    4, Sue, Jones

    MarriageT:
    1, 1, 3
    2, 2, 4

    You can now easily throw these two tables together in a query. Just add MarriageT once and TWO copies of PersonT. Relate together the Spouse fields to the proper IDs, and you're all set.

    Richard Rost
    AccessLearningZone.com

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Richard,
    In MarriageT, what is spouse2?
    And how does it realte to this
    MarriageT:
    1, 1, 3
    2, 2, 4
    Just trying to clarify...

  5. #5
    Amicron's Avatar
    Amicron is offline Access Guru
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Amherst, New York (near Buffalo)
    Posts
    31
    Spouse1 and Spouse2 are the two people who are married. They are foreign keys that relate back to a PersonID. The values in the MarriageT table demonstrate the relationships:

    1,1,3 = ID1, Person #1 is married to Person #3
    2,2,4 = ID2, Person #2 is married to Person #4

  6. #6
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Ok, I saw that. I thought you were trying to show more.

    Let's say any given spouse gets married multiple times.
    The MarriageT would require more fields -- a la Ancestry etc --
    DateOfMarriage, LocationOfMarriage....

    I wasn't seeing how the table could handle anything more than a single " 2 people got married", and I see that's what it was meant to be. However, the poster was looking for a database
    to keep track of marriages.
    and I think the MarriageT is a great start, and now the poster must determine what it is about a marriage that should be recorded/managed.

    Thanks.

  7. #7
    Amicron's Avatar
    Amicron is offline Access Guru
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Amherst, New York (near Buffalo)
    Posts
    31
    Oh, absolutely... this was just to give a basic illustration of how to set up the relationship. You'd want other fields in there to keep track of the details, of course. Perhaps even an IsActive value to recognize if they're still married... or maybe a DivorceDate.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. many-to-many relationship to a single table
    By roleic in forum Database Design
    Replies: 2
    Last Post: 08-01-2012, 03:41 PM
  2. Replies: 2
    Last Post: 06-24-2011, 06:38 AM
  3. doesn't relate
    By mhh12 in forum Programming
    Replies: 1
    Last Post: 08-01-2010, 11:55 AM
  4. Access to Excel transferring multiple rows to single row
    By peter_lawton in forum Import/Export Data
    Replies: 10
    Last Post: 09-23-2009, 10:16 AM
  5. Replies: 1
    Last Post: 07-25-2009, 05:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums