Results 1 to 6 of 6
  1. #1
    keith2511 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2017
    Location
    UK
    Posts
    45

    Query not returning all expected records

    I have a simple database of two tables - parents and children.

    I have written a query with a type 2 join so that all parents and related children are returned.

    However the results omitted two parents that did not have any children.

    What have I done wrong and what should I have done?

    Thanks



    Code:
     SELECT etr.Name, etr.[Organisation Code], etr.[National Grouping], ets.Name, ets.[Organisation Code], ets.[Close Date], ets.HospitalFROM etr LEFT JOIN ets ON etr.[Organisation Code] = ets.[Parent Organisation Code]
    WHERE (((etr.[National Grouping])="y62") AND ((ets.[Close Date]) Is Null) AND ((ets.Hospital)=True) AND ((etr.[Close Date]) Is Null))
    ORDER BY etr.Name;

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    You need an outer join.
    Dbl-click the join line,
    Set it to show all records in the master,
    some recs in child.

  3. #3
    keith2511 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2017
    Location
    UK
    Posts
    45
    Thanks ranman, but isn't that what I've done?

    Click image for larger version. 

Name:	join.PNG 
Views:	21 
Size:	14.1 KB 
ID:	47516

  4. #4
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    and it did not show null records in the child table?
    did you bring down a child record field(s)?

  5. #5
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    I think in the ets.hospital field you need to add Or Is Null to the True in the criteria row.

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  6. #6
    keith2511 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2017
    Location
    UK
    Posts
    45
    Thank you Gicu, I'll give that a go

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

Similar Threads

  1. Replies: 1
    Last Post: 06-09-2020, 01:56 PM
  2. Calling function not returning as expected...
    By sstiebinger in forum Programming
    Replies: 19
    Last Post: 08-18-2015, 02:26 PM
  3. Query not returning expected results
    By MarcieFess in forum Queries
    Replies: 3
    Last Post: 10-18-2013, 05:28 PM
  4. Replies: 3
    Last Post: 07-23-2013, 01:30 PM
  5. Query not returning all expected results
    By amenitytrust in forum Queries
    Replies: 6
    Last Post: 11-05-2012, 07:13 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