Skip to content
Advertisement

What is the difference between count (*) and count(attribute_name)?

Is there any difference between COUNT(*) and COUNT(attribute_name)?

I used count(attribute_name) as I thought that it would be specific hence the searching process would be easier. Is that true?

It would be great to see any example with sql code with my issue to help me understand better

Advertisement

Answer

Imagine this table:

enter image description here

select Count(TelephoneNumber) from Calls -- returns 3
select Count(*) from Calls -- returns 4

count(column_name) also counts duplicate values. Consider:

enter image description here

select Count(TelephoneNumber) from Calls -- returns 4
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement