dcsimg
Results 1 to 11 of 11

Thread: Query within a Query

Hybrid View

  1. #1
    Join Date
    Apr 2009
    Posts
    12

    Query within a Query

    Is there anyway of running a query which has been previously created from with another query???

    Im not talkin about defining a sub query within a query.

    I just mean referencing and running an outside query from within the one you are trying to run??

  2. #2
    Join Date
    May 2006
    Posts
    407
    You can use a pre-existing query within a new query in the same way you would use a table. But other than that, I have no idea of any other way (except the sub-query) to use another query within a query. If you are trying to get an Action query (Update, Delete, Append) to run from within another query, no that does not happen.

  3. #3
    Join Date
    Apr 2009
    Posts
    12
    Thanks GolferGuy. Ive just had to have the solution to the problem in steps of 4 queries to be executed manually 1 after the other.

    Unfortunately I cannot get the 1st one to automatically ececute the other 3.

    Thanks for your help anyway!

  4. #4
    Join Date
    May 2006
    Posts
    407
    Are you dealing with Action Queries (Update, Delete, or Insert)? If so, then you will have to write VBA code or a Macro to run the queries, or continue to do it manually. But if these are queries that are select or crosstab queries, then they will run "automatically" by referencing them as you would a table within another query. In this way, the 4th query would run the three other queries.

  5. #5
    Join Date
    Apr 2009
    Posts
    12
    The queries are not action queries. They merely count rows in another table so that I can use the counted values ina calculation later on. (Access would not allow me to divide by the count function for some reason so I had to count the rows in a table, export them to a seperate table and divide using the field name... If you get what I am saying?)

    Ill try get them to run autoatically now and see what happens.

    Another Quick Question... ......

    Ive posted it in a seperate thread about validation.... Think this one is a none runner though..

  6. #6
    Join Date
    May 2006
    Posts
    407
    If you count the rows in one query, then use that query as the input to the next query (rather than outputting the results of the first query to a table), you can then do calculations on those row counts in the second query. Then that second query can be used as an input source for a third query, etc. There is a limit, but you will not know what it is until Access tells you that what you have put together is too complicated for Access to figure out.

  7. #7
    Join Date
    Apr 2009
    Posts
    12
    How do you do that using the SQL???

    I have tried running the count query without sending the results to a table... and then in the 2nd query I tried referenceing the count but it wont let me???

    Maybe I am doing the SQL wrong??

  8. #8
    Join Date
    May 2006
    Posts
    407
    Because you are "sending the results to a table" that means you are running an Append (insert) query, which is an Action query. Change that to a Select query, then you can use the query itself rather than a table in another query.

  9. #9
    Join Date
    Apr 2009
    Posts
    12
    So after changing it to a select query can i just reference the given field name for the count function?? Even if i change it from the default (Eg: Expr12)

  10. #10
    Join Date
    May 2006
    Posts
    407
    Yes, use that first query as though it were a table, at least as far as the second query goes. Try it before asking, it's a wonderful thing to see it work.

  11. #11
    Join Date
    Apr 2009
    Posts
    12
    Will do! Thanks a million!

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
  •