I'm trying to run a set of nested or stacked queries in Microsoft Access.
As in I run Query 1
-->I use the results of Query 1 in Query 2
---->I use the results of Query 2 in Query 3
------>I use the results of Query 3 in Query 4
Query 3 takes less than 1 second to run.
-- Query 3 results --
PARTID INFO
266 156-10
266 165-10
266 183-10
266 200-10
266 205-10
266 219-10
266 228-10
266 230-10
--end Query 3 results --
When I run Query 4, it takes over a minute to run. Pretty slow. So I tried making a new table (Test_Table) with the results from Query 3. I modified Query 4 to use this table rather than Query 3. Now Query 4 runs in less than 1 second.
Original Slow Query 4 code:
SELECT INVENTORYLOG.TABLEID, INVENTORYLOG.RECORDID, TIINVENTORYLOG.INFO, INVENTORYLOG.TYPEID
FROM Query3 INNER JOIN (TIINVENTORYLOG INNER JOIN INVENTORYLOG ON TIINVENTORYLOG.INVENTORYLOGID = INVENTORYLOG.ID) ON (Query3.PARTID = INVENTORYLOG.PARTID) AND (Query3.INFO = TIINVENTORYLOG.INFO)
WHERE (((INVENTORYLOG.TYPEID)<>40))
ORDER BY TIINVENTORYLOG.INFO;
Modified Fast Query 4 code:
SELECT INVENTORYLOG.TABLEID, INVENTORYLOG.RECORDID, TIINVENTORYLOG.INFO, INVENTORYLOG.TYPEID
FROM Test_Table INNER JOIN (TIINVENTORYLOG INNER JOIN INVENTORYLOG ON TIINVENTORYLOG.INVENTORYLOGID = INVENTORYLOG.ID) ON (Test_Table.info = TIINVENTORYLOG.INFO) AND (Test_Table.partid = INVENTORYLOG.PARTID)
WHERE (((INVENTORYLOG.TYPEID)<>40))
ORDER BY TIINVENTORYLOG.INFO;
Inventorylog has about 23,000 records tiinventorylog has about 18,000 records
So I guess the question is: How do I make Query 4 run quickly using Query 3 instead of my test table?
Thanks for any advice you can give.