Solved

Count(*) vs (ColumnName)

Posted on 2010-09-14
5
452 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 125 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 125 total points
ID: 33674980
the query is all about "email" parameter - for an homogenised formula
0
 
LVL 41

Assisted Solution

by:ralmada
ralmada earned 125 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 70

Assisted Solution

by:Qlemo
Qlemo earned 125 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

696 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