Results 1 to 11 of 11
  1. #1
    BatmanMR287 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jan 2014
    Posts
    69

    Quering Three tables causes duplicates

    I have a report to run that gathers info from three tables. If I make individual queries to get the information I need the three queries gather the correct information. If I make one query it makes duplicates. If I combine the three queries that work the main query mixes up the information and duplicates it. How do you make a query that gets information from three tables and not have it be garbled?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    This indicates the tables have one-to-many or many-to-many relationships. The 'duplication' and 'garbling' would be normal consequences of a query that joins tables with those relationships.

    Options:

    1. report/subreport arrangement

    2. do aggregate queries and then join aggregate queries to each other or to a parent table
    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.

  3. #3
    BatmanMR287 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jan 2014
    Posts
    69
    First table is a one, second is connected and is a many, third is connected to the second and is a many to many.
    Policy Number 2120----------------Administrative Procedure for Policy1 and 2 -----------------Exhibit for Administrative Procedure 1 and 2.
    This has policy name this has ap name this has date of revision and revision notes.
    2120 name 1 2 and names for each date and revision. These are what is need from each table.
    Only data on first tbl this has AP nums(1&2) and policy num this has policy num, AP numbers, and E numbers(1&2) notes and date.

    Not sure how to do a report/subreport and print it.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Sorry, none of that made any sense to me.
    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.

  5. #5
    BatmanMR287 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jan 2014
    Posts
    69
    Ok, basically I have three table with info I want. the query to get info from all tables garbles and duplicates the data. The tables are set up correctly. How do you make a query that gets info from three tables. I have found no reference on the internet on how to do this. Not even anything that says it is or isn't possible.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    I already gave options for data output.
    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.

  7. #7
    BatmanMR287 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jan 2014
    Posts
    69
    Aggregate is for numbers isn't it? I am gathering text, policy numbers, date, and notes for a report.

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Aside from numeric calcs (Sum, Avg, StDev) aggregate can count, get maximum/minimum (even text can have maximum/minimum).

    If you need detail info, not aggregation, then use report/subreport (up to 7 levels I think).
    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.

  9. #9
    BatmanMR287 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jan 2014
    Posts
    69
    I got it. Main table joined to second table as a one to many policyNum to policyNum. Second table joined to third table by TWO joins; PolicyNum to PolicyNum and ENum to ENum. No more duplicates.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Glad you figured it out. Helps to understand the data.
    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.

  11. #11
    BatmanMR287 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jan 2014
    Posts
    69
    This should have worked:
    SELECT Policies.PolicyNum, Policies.PolicyName, PolicyE.ENum, PolicyE.ExhibitName, EUpdates.DateRev, EUpdates.ERevNotes
    FROM PolicyE INNER JOIN (Policies INNER JOIN EUpdates ON Policies.PolicyNum = EUpdates.PolicyNum) ON (Policies.PolicyNum = PolicyE.PolicyNum) AND (PolicyE.PolicyNum = EUpdates.PolicyNum)
    WHERE (((Policies.PolicyNum)=[Forms]![EViewOnlyFrm]![Combo2]));
    This actually worked:
    SELECT EUpdates.PolicyNum, Policies.PolicyName, EUpdates.ENum, PolicyE.ExhibitName, EUpdates.DateRev, EUpdates.ERevNotes
    FROM Policies INNER JOIN (PolicyE INNER JOIN EUpdates ON (PolicyE.PolicyNum = EUpdates.PolicyNum) AND (PolicyE.ENum = EUpdates.ENum)) ON Policies.PolicyNum = PolicyE.PolicyNum
    WHERE (((EUpdates.PolicyNum)=[Forms]![EViewOnlyFrm]![Combo2]));
    No examples anywhere on the internet. Found it by trial and error and logic process.

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

Similar Threads

  1. Find duplicates in three differenct tables
    By mlmelendez in forum Access
    Replies: 4
    Last Post: 06-28-2014, 03:22 PM
  2. Join Two Tables With Duplicates
    By Charles_Access in forum Queries
    Replies: 3
    Last Post: 10-20-2013, 02:12 PM
  3. Delete duplicates from both tables
    By dakpluto in forum Queries
    Replies: 2
    Last Post: 07-02-2012, 04:49 AM
  4. Quering to find a status
    By dbuck in forum Queries
    Replies: 5
    Last Post: 09-08-2010, 02:48 PM
  5. Relationship - Three Tables - No Duplicates
    By Huddle in forum Database Design
    Replies: 15
    Last Post: 07-27-2010, 07:45 AM

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