SchweppesAle Posted May 26, 2010 Share Posted May 26, 2010 Hi, I've used the following query to check for any duplicate email addresses in our table. The problem is, I'm not entirely sure what the difference is between both the having and where clauses so I was hoping someone could confirm whether this would work or not. SELECT COUNT(id) AS Quantity FROM huge_email_list GROUP BY email HAVING ( COUNT(email) = 1 ) My concern is that the query will eliminate email addresses which have multiple entries from the total sum(Quantity) entirely rather than counting them as an additional 1 entry. Is this where the Having clause comes into play? Quote Link to comment Share on other sites More sharing options...
SchweppesAle Posted May 26, 2010 Author Share Posted May 26, 2010 Alright, this clearly wasn't working Thinking that I might just need to include the GROUP BY email clause in order to count the unique email addresses Still, I was hoping someone could clarify the difference between WHERE and HAVING; I really can't tell the difference. Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 26, 2010 Share Posted May 26, 2010 HAVING is almost like WHERE. The difference is, you can use functions and statements in having clause, while you can not in where. Also WHERE coonditions are applied before HAVING conditions. Quote Link to comment Share on other sites More sharing options...
SchweppesAle Posted May 26, 2010 Author Share Posted May 26, 2010 HAVING is almost like WHERE. The difference is, you can use functions and statements in having clause, while you can not in where. Also WHERE coonditions are applied before HAVING conditions. Thanks for clearing that up Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 26, 2010 Share Posted May 26, 2010 There are in fact further differences, but those are essential I think. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.