Results 1 to 3 of 3
  1. #1
    roleic is offline Novice
    Windows XP Access 2003
    Join Date
    Jul 2010
    Posts
    1

    many-to-many relationship to a single table

    Situation:


    I have a table "Pupils" with a primary key "pupil" and have the entries john, mary, billy, susan, marc in it.

    Now I would like to enter the information that john, billy and susan are siblings.

    So I created another table "Siblings" with two combined primary keys "pupil_A" and "pupil_B". Then I introduced a 1-to many relationship from pupil in table Pupils to pupil_A and onother one from pupil in table Pupils_1 (instance of Pupils in the relationship window) to pupil_B.
    This worked perfectly. In Siblings I can enter now john and billy, john and susan, billy and susan.

    Problem:
    What disturbs me is that I can without any error message also enter the reverse relationship billy and john which is a redundant entry to john and billy. Moreover I can also enter john and john.

    Question:
    How can I prevent the above two kinds of entries?

  2. #2
    ConneXionLost's Avatar
    ConneXionLost is offline Simulacrum
    Windows XP Access 2003
    Join Date
    Jan 2010
    Location
    Victoria, Canada
    Posts
    291
    You will need three tables. Use your original "tblPupil" table, a "tblFamily" table, and a "tblFamilyMember" table.

    In tblFamily, you would have FamilyID (PK), Surname, etc. The data would/could be: Smith, Jones, Miller, etc.

    In tblFamilyMember, you would have FamilyID & PupilID as a composite PK.

    Cheers,

  3. #3
    jameslarsen is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2012
    Location
    Los Angeles, CA
    Posts
    20
    Most likely you will need to do this with code. Access cannot interpret data, and doesn't understand that John / Susan is the same as Susan / John, or that John cannot be joined to himself. What I have done in similar situations is to build an interface to add new people, and as part of the add procedure, it would take the two names, and run a few VBA queries. First it would check if the two names matched each other. Assuming they did not, it would then run a query that reversed the names, and see if any results were returned. If no results came back, only then would it execute an insert statement into the "Siblings" table with the IDs of the two people being linked. Unfortunately I don't know of any easy ways to accomplish this using the Access GUI builder.

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

Similar Threads

  1. Searching for a single word in all table
    By rielcas in forum Access
    Replies: 1
    Last Post: 06-19-2013, 06:28 AM
  2. Replies: 5
    Last Post: 03-23-2011, 10:39 AM
  3. Create Multiple Charts from Single Table
    By Catch Wrestler in forum Reports
    Replies: 0
    Last Post: 06-17-2010, 08:33 AM
  4. Table related to multiple tables by single ID
    By MrTumnus in forum Access
    Replies: 1
    Last Post: 11-17-2009, 02:05 PM
  5. Show two tables in single table
    By access in forum Forms
    Replies: 8
    Last Post: 06-11-2009, 11:57 AM

Tags for this Thread

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