Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which query is more efficient?

Status
Not open for further replies.

ZABADAK

Programmer
Feb 24, 2005
39
US
Which of the following is more efficient, or is there no difference?

SELECT tblSSRData.*, tblPriority.Desc AS PriDesc, tblPriority.Target AS PriTarg
FROM tblSSRData, qryMaxThru, tblPriority
WHERE (((tblSSRData.[SSR_#])=[qryMaxThru].[SSR_#]) AND ((tblSSRData.[TASK_#])=[QryMaxThru].[Task_#]) AND ((qryMaxThru.Max_Thru_Date)=[tblSSRData].[REPORT_THRU_DATE]) AND ((tblSSRData.PRI)=[tblPriority].
Code:
));

SELECT tblSSRData.*, tblPriority.Desc AS PriDesc, tblPriority.Target AS PriTarg
FROM (tblSSRData INNER JOIN tblPriority ON tblSSRData.PRI = tblPriority.Code) INNER JOIN qryMaxThru ON (tblSSRData.[SSR_#] = qryMaxThru.[SSR_#]) AND (tblSSRData.[TASK_#] = qryMaxThru.[Task_#]) AND (tblSSRData.REPORT_THRU_DATE = qryMaxThru.Max_Thru_Date);
 
It's not impoossible that the first could be more efficient with Access and Jet. Access prefers the newer syntax and may well therefore not optimise the second query as thoroughly

 
The so-called Access guru that sits next to me sat work said the second one would run faster. He composes his queries with the Access tool whereas I always code in raw SQL. I can't really tell which is faster. Since Access has no profiler tool, I don't know how to tell.
 
Since Access has no profiler tool, I don't know how to tell.

You could write a short bit of code which reads the system clock into one variable, runs the query, then reads the system clock again and subtracts one from the other:

Code:
timStart = Time()
DoCmd RunSQL strSQL
timEnd = Time()
?DateDiff("s", timStart, timEnd)

It's not perfect but it'll give an idea of the timing to the nearest second. If the queries take a fraction of a second to run then you might have to time them over a hundred times in a loop.

On the other hand, does it really matter if the query takes a tenth of a second or a hundredth of a second. Computer time is cheap - developer time is expensive.

Geoff Franklin
 
It does matter to me because I am handling huge volumes of data. This is a table that accumulates data over the months and gets bigger and bigger. It should really be in SQL Server but they don't have enough servers here. By the way computer time is not cheap. We are charged for each cpu second.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top