简体   繁体   中英

MS-Access SQL Query Performance - Slow

I have a query that pulls data and joins from other queries. The final query is taking about 8 minutes to run. Is there a more efficient way to query the information from queries built on queries (such as creating a table with the results of the first queries OR building an index - OR ??).

My final query is as simple as:

SELECT Filtered_ZFEWN.[Base 8], Filtered_ZFEWN.Notification, Filtered_ZFEWN.
[Service Product], Filtered_ZFEWN.[Product Hierarchy]
FROM Filtered_ZFEWN RIGHT JOIN 
    Notifications_by_Base_8 ON Filtered_ZFEWN.[Base 8] = 
    Notifications_by_Base_8.[ZFEWN Base 8]
WHERE Notifications_by_Base_8.[Product Hierarchy] IN 
    (SELECT Notifications_by_Base_8.[Product Hierarchy] 
     FROM Notifications_by_Base_8 
     WHERE Notifications_by_Base_8.[Product Hierarchy] NOT LIKE "*MISC*");

This query is pulling data from 6 other queries (you can see it explicitly pulls from two queries, but the other queries are also built upon 4 queries). I am looking for performance improvement.

By adding the wildcard at the beginning of the Like "*MISC*" , you are stopping Access using any indexes on the sub query.

This will slow it down significantly on a larger dataset.

Can you move the filtering for that earlier in the query chain, or remove then starting wildcard? Or build an In clause without the Not Clause?

Isn't the subquery (query after the IN key word) redundant and always returns the same result? – Peeyush 15 hours ago

@peeyush You are correct - That is the answer. I removed the select subquery and kept only the NOT LIKE "misc" portion and this ran in 8 seconds. Thank you!!! – Analyst123456789 11 secs ago edit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM