Results 1 to 4 of 4
  1. #1
    trussell is offline Novice
    Windows 10 Access 2016
    Join Date
    Jun 2021
    Posts
    5

    Using Query Results as a Criteria for Another Query

    Hi everyone,



    Is it possible to use the output of another query as the criteria for a different query? To be specific, I have two queries. In Query 1 I have a criteria for a client name (the user inputs the client name they are interested in), which spits out a table that includes the client name and corresponding "Order ID". In query 2, it would need to look at the output from Query 1 and, using the remaining "Order ID's", apply an additional filter based on a date range specified by the user.

    How would I go about implementing this?
    Any advice would be appreciated. Thanks!

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I think what you're asking about is known as a stacked query where a query is used to provide a 'filtered' recordset to a 2nd query. You add the query to the 2nd query as you would a table. Why wouldn't you just use the date criteria in the first query as well as the client id?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    I'm not really sure what your situation is but I imagine a query like this

    Code:
    
    SELECT * 
    FROM   order_table 
    WHERE  order_table.order_date BETWEEN [ENTER STARTING DATE] AND [ENTER ENDING DATE] 
           AND order_table.customer_id = (SELECT TOP 1 customer_table.customer_id 
                                          FROM   customer_table 
                                          WHERE  customer_table.customer_name = [ENTER CUSTOMER NAME]);
    

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    don't see why you cant just have an ordinary query with two criteria. Not clear what you mean by remaining OrderID's - all of them? just for this customer?


    Assuming the latter and amending kd's code

    Code:
    SELECT * 
    
    FROM   order_table LEFT JOIN Customer_table ON Order_table.customer_id=customer_table.customer_id
    
    WHERE  order_table.order_date BETWEEN [ENTER STARTING DATE] AND [ENTER ENDING DATE] 
           AND order_table.customer_name = [ENTER CUSTOMER NAME]
           AND order_table.order_id<>customer_table.order_id

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

Similar Threads

  1. Replies: 1
    Last Post: 03-16-2017, 12:29 PM
  2. Replies: 5
    Last Post: 09-05-2016, 09:07 AM
  3. query with criteria and no results
    By macattack03 in forum Queries
    Replies: 3
    Last Post: 11-04-2013, 11:19 AM
  4. Replies: 3
    Last Post: 05-02-2013, 10:36 AM
  5. query results as criteria
    By tuyo in forum Queries
    Replies: 2
    Last Post: 03-23-2011, 04:30 PM

Tags for this Thread

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