Major difference between COUNT(column_name) and COUNT(*)

Post here if you need help with SQL.
Post Reply
Fidbeck
Posts: 147
Joined: Tue Sep 25, 2012 11:40 pm

Major difference between COUNT(column_name) and COUNT(*)

Post by Fidbeck »

For example if I wanted to count elements in a specific table
I can use
SELECT COUNT(user_id) FROM `users`
and
SELECT COUNT(user_id) FROM `users`
the give the same number but what are the main differences between them?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Major difference between COUNT(column_name) and COUNT(*)

Post by jacek »

The difference is generally performance on large tables, this explains it rather well http://www.mysqlperformanceblog.com/200 ... -countcol/
Image
Fidbeck
Posts: 147
Joined: Tue Sep 25, 2012 11:40 pm

Re: Major difference between COUNT(column_name) and COUNT(*)

Post by Fidbeck »

My table is not that big it has over 100 users, so I can use either. but for the sake of speed count(*) is faster

Thanks
Post Reply