Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2010
    Posts
    3

    Unhappy Returning correct rows in a join/nested query

    First off I have two tables that are set up similiar to what you see below (of course different columns and data):




    Next I have a form that allows you to search by an Order date:


    And now what I want the query to return is the following: If the date matches ANY of the OrderDate values in the Orders table then it will spit back the Customer information (Customer.*) who made that order and ALL other rows for that particular customer in the Orders table. Perhaps most importantly I can't pass the name of the customer or a date range or anything else, I want to do this using just the date variable from the form so no hard coding to fix the issue.

    My current query more or less looks like this:
    SELECT Customer.*, Orders.*
    FROM Customer LEFT JOIN Orders ON Customer.CustomerID = Orders.CustomerID
    WHERE Orders.OrderDate=[Forms]![DateSearch].[OrderDateInputBox];

    I have a report that builds out fine but it will only spit back the matching customer(s) from the Customers table and (here is the problem) ONLY the MATCHING rows from the Orders table. Make sense?

    THANKS FOR ANY HELP YOU CAN PROVIDE

  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,521
    Shot in the dark, but try

    WHERE Orders.CustomerID IN(SELECT CustomerID FROM Orders WHERE OrderDate = [Forms]![DateSearch].[OrderDateInputBox])
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Join Date
    Mar 2010
    Posts
    3
    Quote Originally Posted by pbaldy View Post
    Shot in the dark, but try

    WHERE Orders.CustomerID IN(SELECT CustomerID FROM Orders WHERE OrderDate = [Forms]![DateSearch].[OrderDateInputBox])

    You Sir are a fine American and SQL Hero. That worked. I knew it would be much easier once it was solved. Thank you again!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Glad it helped. It occurs to me that you could also make the subquery a stand-alone query, and then join to it instead of using it in the WHERE clause. It would probably be more efficient if there are a lot of records.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  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,521
    Oh, and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    Join Date
    Mar 2010
    Posts
    3
    Quote Originally Posted by pbaldy View Post
    Oh, and welcome to the site by the way!
    Thanks very much... I hope that this thread helps others in need and that I can continue to rely on all the knowledge here, its been great so far.

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

Similar Threads

  1. Join Query?
    By KWarzala in forum Forms
    Replies: 5
    Last Post: 07-29-2014, 02:44 PM
  2. inner join in query
    By Hrcko in forum Access
    Replies: 1
    Last Post: 02-01-2010, 05:54 PM
  3. Stuck on Join Query
    By Pimped in forum Queries
    Replies: 1
    Last Post: 10-26-2009, 10:54 AM
  4. Replies: 1
    Last Post: 09-19-2006, 11:07 AM
  5. Nested IIf query will not work
    By ddog171 in forum Queries
    Replies: 1
    Last Post: 06-20-2006, 02:03 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