Jump to content

How to use the Having Clause


SchweppesAle

Recommended Posts

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? 

Link to comment
Share on other sites

Alright, this clearly wasn't working :P

 

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.