Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Count(*) vs (ColumnName)

Posted on 2010-09-14
5
Medium Priority
?
453 Views
Last Modified: 2012-05-10
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
Comment
Question by:Mr_Shaw
5 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 33674977
count(*) counts rows

count(email) counts rows that have a non-null value for email
0
 
LVL 4

Assisted Solution

by:ronan1979
ronan1979 earned 500 total points
ID: 33674980
the query is all about "email" parameter - for an homogenised formula
0
 
LVL 41

Assisted Solution

by:ralmada
ralmada earned 500 total points
ID: 33674985

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
 
LVL 71

Assisted Solution

by:Qlemo
Qlemo earned 500 total points
ID: 33675192
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
 

Author Closing Comment

by:Mr_Shaw
ID: 33680652
thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question