Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

Count(*) vs (ColumnName)

in the article on http://www.petefreitag.com/item/169.cfm the author uses the following SQL code:

SELECT email,
 COUNT(email) AS NumOccurrences
FROM users
GROUP BY email
HAVING ( COUNT(email) > 1 )

Is there any reason why they did not use count(*) instead of count(email) ?
0
Mr_Shaw
Asked:
Mr_Shaw
4 Solutions
 
sdstuberCommented:
count(*) counts rows

count(email) counts rows that have a non-null value for email
0
 
ronan1979Commented:
the query is all about "email" parameter - for an homogenised formula
0
 
ralmadaCommented:

COUNT(*) returns the number of items in a group. This includes NULL values and duplicates.
COUNT(email) evaluates expression for each row in a group and returns the number of nonnull values
Different result
 
more info
 
http://msdn.microsoft.com/en-us/library/ms175997.aspx 
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
You could use this equivalent:

SELECT email,
 COUNT(*) AS NumOccurrences
FROM users
where email is not null
GROUP BY email
HAVING ( COUNT(email) > 1 )


0
 
Mr_ShawAuthor Commented:
thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now