This is a sql query that I am using in a page that I am building. It currently runs about 8 seconds and returns 12000 records, which is correct but I am wondering if you could make possible suggestion as to how I could make it faster?
SELECT DISTINCT Advertiser.AdvertiserID, Business.Name, Business.Address1, Business.Address2, Business.City, Business.State, Business.PostalCode,
Business.Country, Business.Phone, Business.Fax, Business.Email, AdvertiserCategory.CategoryID, AdvertiserCategory.CategoryName AS Category,
(SELECT MAX(PubDate) AS PubDate
FROM NewsPaperAd
WHERE (AdvertiserID = Advertiser.AdvertiserID)
GROUP BY AdvertiserID) AS PubDate
FROM Business INNER JOIN
Advertiser ON Business.BusinessID = Advertiser.AdvertiserID INNER JOIN
Tsheetrecipient ON Advertiser.AdvertiserID = Tsheetrecipient.AdvertiserID LEFT OUTER JOIN
AdvertiserCategory INNER JOIN
AdvertiserCategoryJoin ON AdvertiserCategory.CategoryID = AdvertiserCategoryJoin.CategoryID ON
Advertiser.AdvertiserID = AdvertiserCategoryJoin.AdvertiserID
WHERE ((SELECT MAX(PubDate) AS PubDate
FROM NewsPaperAd AS NewsPaperAd_1
WHERE (AdvertiserID = Advertiser.AdvertiserID)
GROUP BY AdvertiserID) IS NOT NULL)
ORDER BY PubDate DESC
I'm really wondering what alternatives there are to the group by clause as this is what is really slowing it down.
Thanks