Results 1 to 10 of 10
  1. #1
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265

    Two primary keys to the same field?

    I have the following:

    tblEmployees: Employee ID = Primary Key
    tblSubcontractors: Employee ID = Primary Key
    Table3: Employee ID = Foreign Key


    The first two tables have a unique set of employeeID numbers. The third table, contains employeeIDs that appear in the first two tables. I have the primary keys from both tables joined to the foreign key in the third table. The results come up blank.

    However, if I join only table #1 or #2 to the third table, then I do get results.

    It seems like you cannot have two primary keys joined to the same foreign key. Is this correct? If so, is there a way around this?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Not quite sure what you have there. Is the tblEmployees: Employee ID = Primary Key the SAME VALUE as the tblSubcontractors: Employee ID = Primary Key?

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Are you using INNER JOIN in the query?

    Why do you have two tables for employees?

    Are both of those primary keys autonumber type or are they custom ID?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I would have:
    Code:
    tblEmployees: EmployeeID = Primary Key
    
    tblSubcontractors: SubcontractorID = Primary Key
    
    Table3:       Table3ID = Primary Key (autonumbr
                EmployeeID = Foreign Key
           SubcontractorID = Foreign Key

  5. #5
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265
    Quote Originally Posted by RuralGuy View Post
    Not quite sure what you have there. Is the tblEmployees: Employee ID = Primary Key the SAME VALUE as the tblSubcontractors: Employee ID = Primary Key?
    The employee ID values in table 1 and 2 are not the same.

  6. #6
    Access_Novice is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Sep 2013
    Posts
    265
    Quote Originally Posted by June7 View Post
    Are you using INNER JOIN in the query?

    Why do you have two tables for employees?

    Are both of those primary keys autonumber type or are they custom ID?
    One table is for employees. The other table is for subcontractors. Each employee has a unique ID number (alpha numeric). Each subcontractor has a unique ID number (also alphanumeric).

    The subcontractor IDs do not duplicate the employee IDs. I just thought it would be better organization split out the employees from the subcontractors.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I'll bow out for now.

  8. #8
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Text type fields are not very good as PK fields. You might want to read these:

    Autonumbers--What they are NOT and What They Are
    http://www.utteraccess.com/wiki/index.php/Autonumbers


    Microsoft Access Tables: Primary Key Tips and Techniques
    http://www.fmsinc.com/free/newtips/primarykey.asp


    Use Autonumbers properly
    http://access.mvps.org/access/general/gen0025.htm

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    To reduce confusion, change to ContractorID.

    What is purpose of Table3?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    It might be helpful to users if you would tell us a little about your database and its purpose.
    What do each of the tables represent in your "business"?

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

Similar Threads

  1. Question about Primary Keys
    By Helystra in forum Database Design
    Replies: 3
    Last Post: 11-21-2013, 03:56 PM
  2. primary keys in four different tables
    By greatlhanderz_15 in forum Access
    Replies: 5
    Last Post: 01-30-2013, 10:04 PM
  3. How to create two primary keys
    By Shabana123 in forum Database Design
    Replies: 1
    Last Post: 09-08-2012, 05:55 AM
  4. primary/foreign keys
    By st1300 in forum Database Design
    Replies: 38
    Last Post: 12-04-2011, 01:27 PM
  5. Query using the same primary keys.
    By Franuzz in forum Queries
    Replies: 1
    Last Post: 04-11-2011, 11:27 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