How do I write this SQL so that it execute faster?
Posted on 2011-05-09
Is there a way to write this SQL differently so that it execute faster.
I would like to do it without adding index.
SELECT DISTINCT Customers.CustomerID
FROM Customers LEFT OUTER JOIN
aspnet_Membership ON Customers.NetUserID = aspnet_Membership.UserId LEFT OUTER JOIN
Wishlists ON Customers.CustomerID = Wishlists.CustomerID LEFT OUTER JOIN
blog ON Customers.CustomerID = blog.CustomerID
WHERE (Wishlists.Comments <> N'') AND (aspnet_Membership.CreateDate >= DATEADD(Day, DATEDIFF(Day, 0, GETDATE() - 7), 0))
GROUP BY Customers.CustomerID
HAVING (COUNT(blog.Comment) = 0)
- Hash Match (Affrefate) Cost: 57%
- Clusted Index Scan (clustered) [blog].[PK_blog_1] Cost: 24%
I use SQL Server 2008