Results 1 to 5 of 5
  1. #1
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    159

    Which SQL technique is smarter?

    A recent thread made me question which way of doing the same thing is the "better" way. I'd like to know which is least demanding on the processor. I've pasted the queries and the results below, but it's basically an expression field containing a DMax() function or an expression field with a nested Select Max() statement. From behavior, I guess the nested select is more versatile because you can include a WHERE clause, but the DMax() resultset has the advantage of still being able to append new records. That's nice and all, but I'm wondering which executes faster.



    Does the processor really have to run every single row against its own DMax() or nested Select? Can't the "brain" of the database first solve for the Max value only one time, and then remember that value for use in each row of the expression field?

    Click image for larger version. 

Name:	DMax-Nested Select.jpg 
Views:	19 
Size:	119.4 KB 
ID:	27025

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    do NOT use Dmax in a query. Its running twice as many functions.
    The query IS the Dmax, so just run the query total.

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    fastest way would be to use a second query

    SELECT *
    FROM Table1 T LEFT JOIN (SELECT Max(reportDate|) as MaxDate FROM Table1) M ON T.ReportDate=M.MaxDate

    Other thing that will affect performance is indexing - if table is long, then index reportdate

  4. #4
    MatthewGrace is offline Competent Performer
    Windows 8 Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    159
    Ajax: very interesting - I never thought to do it this way. I entered the SQL you gave me, and in design view it is represented visually but not in the fields below. Nevertheless, it is not complicated I get exactly what you mean.

    Ranman: Thank you for your input, but I'm not sure I understand. Are you suggesting DMax should never be used in a function, if so why? Do you agree with Ajax's concept?

    Both: After looking at my graphic above, notice the expression field contains either DMax or SELECT... am I correct in assuming that Access needs to run again and again and again that same Dmax or SELECT for every single row in the resulting recordset? If so, I can see why that would be resource demanding.

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    am I correct in assuming that Access needs to run again and again and again that same Dmax or SELECT for every single row in the resulting recordset?
    for your two versions - yes, although for the subquery, the dbengine will do some optimising. You might find this link of interest

    https://www.experts-exchange.com/art...Functions.html

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

Similar Threads

  1. Replies: 10
    Last Post: 08-24-2015, 04:44 PM
  2. Replies: 1
    Last Post: 08-19-2015, 09:35 PM
  3. Mousewheel dll technique
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-24-2010, 04:13 PM
  4. Help with a smarter form
    By m.hatter in forum Forms
    Replies: 17
    Last Post: 12-12-2009, 12:06 PM

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