Results 1 to 3 of 3
  1. #1
    T_Tronix is offline Novice
    Windows 8 Access 2007
    Join Date
    Nov 2013
    Posts
    28

    Combining 2 queries into one for combobox

    I have the following 3 queries, one does one thing, the 2nd one another thing and the 3rd merges both. But when one of the queries returns a null value the merged query seems to give me a null result even though there are values in the second query.



    Q1:

    Code:
    SELECT Tasks.Resource_F, Tasks.Resource_LFROM Tasks, CachedDates
    WHERE (((Tasks.Start_Date)<[CachedDates].[SDate] Or (Tasks.Start_Date)>[CachedDates].[EDate]) AND ((Tasks.End_Date)<[CachedDates].[SDate] Or (Tasks.End_Date)>[CachedDates].[EDate]));
    Q2:

    Code:
    SELECT DISTINCT Employees.First_Name, Employees.Last_NameFROM Employees LEFT JOIN Tasks ON Employees.ACF2_ID = Tasks.Resource_ACF2ID
    WHERE (((Tasks.Resource_ACF2ID) Is Null));
    Merged Query:

    Code:
    SELECT DISTINCT Employees.First_Name, Employees.Last_NameFROM Employees, Q2_NamesNotInTasks, Q1_AvailableNamesInTasks
    WHERE (((Employees.ACF2_ID)=[Q1_AvailableNamesInTasks].[Resource_ACF2ID] Or (Employees.ACF2_ID)=[Q2_NamesNotInTasks].[ACF2_ID])) OR (((Q1_AvailableNamesInTasks.Resource_ACF2ID) Is Null));

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    But when one of the queries returns a null value the merged query seems to give me a null result even though there are values in the second query.
    Do you mean when one of the queries returns no records, your final merged query returns no records?
    That is to be expected, as your merged query has no joins in it. If there are no joins, it returns the Cartesian Product of all the objects (tables, queries) contained in it.
    To determine the number of records returned in a Cartesian Product, it is the product (multiplication) of the number of records in each object.
    Anything times zero will return zero!

    The only way to get records to return in a query where one of the objects has zero records is to do an Outer Join (Left or Right).

    Here is some info on Cartesian Products in Access: http://accessdatabasetutorial.com/20...ins-in-access/
    There are other articles on it too, if you Google "Access Cartesian Product"

  3. #3
    T_Tronix is offline Novice
    Windows 8 Access 2007
    Join Date
    Nov 2013
    Posts
    28
    Thanks it worked! Just had to add a relationships in between the tables...

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

Similar Threads

  1. Combining queries
    By jamo in forum Queries
    Replies: 11
    Last Post: 11-09-2012, 07:36 AM
  2. Combining two queries.
    By Ray67 in forum Queries
    Replies: 1
    Last Post: 09-07-2012, 12:11 PM
  3. Combining queries..
    By Anthony88 in forum Queries
    Replies: 4
    Last Post: 05-02-2012, 02:46 PM
  4. combining two queries
    By camell in forum Queries
    Replies: 4
    Last Post: 03-04-2011, 02:41 PM
  5. Combining Two Queries
    By csolomon in forum Queries
    Replies: 1
    Last Post: 09-03-2009, 01:33 PM

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