Results 1 to 7 of 7
  1. #1
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    list all records in query based on relationship

    Hi

    I have a database with three tables, tbl_deceased.tbl_join and tbl_Memorial. Not every deceased person has a memorial. The relationship is many to many between memorials and deceased hence the join table



    tbl_Deceased contains 39741 records

    tbl_join contains 39741 records



    both are linked by graveId and fkgraveID


    tbl_Memorials contains 17699 records

    and is linked to tbl join by MemorialID and fkMemorialID


    If I create a query using all three tables

    I only see 25482 records

    If I delete tbl_memorial from the query and run it I see 39741 records.

    Is this correct or have I missed a tick box?



    thanks

    Ian
    Attached Thumbnails Attached Thumbnails relationship.jpg  

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    If your question is how to see the "missing" records in the query, double click on the join line to that table in the query to edit it. The correct choice should be evident.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    The default join is an "INNER JOIN", which only returns records that have matches.
    If you want to return records for ALL deceased members, regardless of whether or not they have had any Memorials, you will need to do a LEFT JOIN between your tblDeceased and tblJoin tables.

    If you double-click on the Join line shown above between the two tables, it will allow you to do this easily. Just select the appopriate option (the one that begins someone like "Show all records from the tblDeceased table...".

  4. #4
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453
    Hi Guys

    As usual so simple when you know!!!

    thanks

    Ian

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    You're welcome!

  7. #7
    Jen0dorf is offline Competent Performer
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    UK
    Posts
    453

    all records inner and outer join

    Hi

    deep and abject apologies if I ramble on but I am as usual confused.

    Have a query based on a three tables (tbl deceased, tbljoin and tbl memorial) that when run does not show all records. I realised that Not all records in tbl memorials have matching entries in tbl join.

    The relationship is

    Click image for larger version. 

Name:	qry_relationship.jpg 
Views:	9 
Size:	61.6 KB 
ID:	24922

    Courtesy of the forum I found right clicking on the join of a query gave me three options.

    My original query is below and is I think an inner join only showing matching records
    Code:
    SELECT tblDeceased.GraveID, tblDeceased.Mlink, tblDeceased.Plot, tblDeceased.GraveNo, tblDeceased.Forenames, tblDeceased.Surname, tblDeceased.Age, tblDeceased.DayOfDeath, tblDeceased.MonthOfDeath, tblDeceased.YearOfDeath, tblDeceased.DayOfBurial, tblDeceased.MonthOfBurial, tblDeceased.YearOfBurial, tblDeceased.Inscription AS tblDeceased_Inscription, tblDeceased.pp, tblDeceased.Notes, tblDeceased.Links, tblDeceased.map, tblDeceased.notes_2, [tblDeceased]![Notes] & " " & [tblDeceased]![notes_2] AS [Complete Notes], tblDeceased.pdfMap, tblDeceased.GraveNotes, CDate([DayOfBurial] & "/" & [MonthOfBurial] & "/" & [YearOfBurial]) AS FullDateofBurial, CDate([DayOfDeath] & "/" & [MonthOfDeath] & "/" & [YearOfDeath]) AS FullDateofDeath, tblMemorial.Mlink, tblMemorial.Inscription
    FROM tblMemorial INNER JOIN (tblDeceased INNER JOIN tblJoin ON tblDeceased.GraveID = tblJoin.fkGraveID) ON tblMemorial.MemorialID = tblJoin.fkMemorialId
    ORDER BY tblDeceased.Forenames;
    So I selected option two in the join between tbljoin and tbl memorial so that "All records from tbl memorial are included and only those from tbljoin where the joined fields are equal

    Code:
    SELECT tblDeceased.GraveID, tblDeceased.Mlink, tblDeceased.Plot, tblDeceased.GraveNo, tblDeceased.Forenames, tblDeceased.Surname, tblDeceased.Age, tblDeceased.DayOfDeath, tblDeceased.MonthOfDeath, tblDeceased.YearOfDeath, tblDeceased.DayOfBurial, tblDeceased.MonthOfBurial, tblDeceased.YearOfBurial, tblDeceased.Inscription AS tblDeceased_Inscription, tblDeceased.pp, tblDeceased.Notes, tblDeceased.Links, tblDeceased.map, tblDeceased.notes_2, [tblDeceased]![Notes] & " " & [tblDeceased]![notes_2] AS [Complete Notes], tblDeceased.pdfMap, tblDeceased.GraveNotes, CDate([DayOfBurial] & "/" & [MonthOfBurial] & "/" & [YearOfBurial]) AS FullDateofBurial, CDate([DayOfDeath] & "/" & [MonthOfDeath] & "/" & [YearOfDeath]) AS FullDateofDeath, tblMemorial.Mlink, tblMemorial.Inscription
    FROM tblMemorial LEFT JOIN (tblDeceased INNER JOIN tblJoin ON tblDeceased.GraveID = tblJoin.fkGraveID) ON tblMemorial.MemorialID = tblJoin.fkMemorialId
    ORDER BY tblDeceased.Forenames;
    My logic was that this woud show me all records from the tbl memorials

    However I get an error that cofused me about inner and outer joins

    The SQL statement could not be executed because it contains ambiguous outer joins. To force one of the joins to be performed first, create a separate query that performs the first join and then include that query in your SQL statement.

    I've searched google and it seems to be a common error but I can't find a solution

    thanks

    Ian
    Last edited by Jen0dorf; 06-17-2016 at 04:30 AM. Reason: used wrong coding wrapper

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

Similar Threads

  1. Replies: 1
    Last Post: 10-21-2015, 05:16 PM
  2. Replies: 13
    Last Post: 11-27-2014, 10:18 AM
  3. Replies: 2
    Last Post: 08-13-2014, 09:38 AM
  4. VBA for records based on cbo Value List
    By libraccess in forum Programming
    Replies: 3
    Last Post: 02-22-2013, 02:39 AM
  5. Replies: 14
    Last Post: 12-06-2012, 11:25 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