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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Really slow query

Status
Not open for further replies.

wvandenberg

Technical User
Oct 24, 2002
125
CA
I have a query that is really slow and I was wondering if I can tweak the SQL somehow to speed it up.

Code:
SELECT DISTINCT A.pkSiteID, A.SiteNameDescription, A.Easting, A.Northing, A.SiteName, A.WaterUnit, A.WaterUnitType, A.Parent
FROM tblWizTempALS, [SELECT pkSiteID, SiteName, SiteNameDescription, Easting, Northing, tlkpWaterUnits.WaterUnit, tlkpWaterUnits.WaterUnitType, P_WaterUnits.WaterUnit AS Parent FROM (tlkpWaterUnits LEFT JOIN tlkpWaterUnits AS P_WaterUnits ON tlkpWaterUnits.ParentID = P_WaterUnits.pkWaterUnitID) RIGHT JOIN tblSites ON tlkpWaterUnits.pkWaterUnitID = tblSites.fkWaterUnitID ORDER BY SiteName, tlkpWaterUnits.WaterUnit, P_WaterUnits.WaterUnit]. AS A, tblWizTempGAL
WHERE (((A.SiteName) Like "*" & Left([CLIENTID],3) & "*") AND ((tblWizTempALS.CLIENTID)='CR-1')) OR (((A.Easting)<[tblWizTempGal].[Easting]+100 And (A.Easting)>[tblWizTempGal].[Easting]-100) AND ((A.Northing)<[tblWizTempGal].[Northing]+100 And (A.Northing)>[tblWizTempGal].[Northing]-100))
ORDER BY A.SiteName, A.WaterUnit;

Any advice is greatly appreciated.

Thanks,
Wendy
 
Remove the ORDER BY clause in the subquery (A).

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
BTW, you really need the DISTINCT predicate ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV, I removed the ORDER BY clause in the subquery (A). However, I do need the DISTINCT predicate. The query isn't any faster. Should I split it into two queries and use a union query to join it together?

Wendy
 
How is tblWizTempGal related to the other table(s)? Are there multiple entries in it?

Greg
People demand freedom of speech as a compensation for the freedom of thought which they seldom use. Kierkegaard
 
Greg, tblWizTempGal is an intermediate table into which I import a data file. Then I use queries to append the data to the appropriate tables in my database. Yes, there are multiple entries.

Wendy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top