Computer Learning Zone CLZ Access Excel Word Windows

Change is the end result of all true learning.

-Leo Buscaglia
 
Home   Courses   TechHelp   Forums   Help   Contact   Merch   Join   Order   Logon  
 
Back to Visitor Forum    Comments List
Upload Images   @Reply   Bookmark    Link   Email   Next Unseen 
MaxDate Subquery
Paul James 

3 years ago
Hi both Kevin and Rich, thank you both for the fast response. Between your videos and by Access 2019 bible i have two databases up and running, so thanks again. I never thought to use a sub query. If I use a small aggregate subqury within the outer query as the where clause? Will that return all the fields? Thanks again Paul from UK becoming a silver member
Kevin Yip  @Reply  
     
3 years ago
You put the WHERE clause in the query that is more time-consuming to run -- because WHERE limits the number of records to be processed, thus improving performance.

For instance:

     SELECT a.ProductID, a.ProductDesc, b.TotalCost FROM ProductsT AS a
     INNER JOIN (
          SELECT ProductID, Sum([ProductCost]) AS TotalCost
          FROM ProductSalesT
          GROUP BY ProductID
          HAVING ProductID = "12345"
     ) AS b
     ON a.ProductID = b.ProductID

is more efficient than:

     SELECT a.ProductID, a.ProductDesc, b.TotalCost FROM ProductsT AS a
     INNER JOIN (
          SELECT ProductID, Sum([ProductCost]) AS TotalCost
          FROM ProductSalesT
          GROUP BY ProductID
     ) AS b
     ON a.ProductID = b.ProductID
     WHERE a.ProductID = "12345"

even though they (likely) will return the same result.

That's because in the former, the condition ProductID = "12345" is put inside instead of outside.  The inside query is a summation query, which is more time-consuming to perform.  Hence, putting a condition there will help the performance.

Btw, this above method uses "nested queries", which essentially let you run multiple queries with just one query.  The performance hit is not very big if the number of records being processed is kept in check.  

You can split them up into two queries, if you prefer.  But the placement of WHERE should follow the same rule -- you put it in the query that potentially retrieves the most records.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Visitor Forum.
 

Next Unseen

 
New Feature: Comment Live View
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2026 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 5/6/2026 10:11:31 AM. PLT: 1s