what is count(*), count(column_name) and count(distinct column_name) ?
suppose we have employee table and having 100 records.
you all know what is count(*) in sql, this all function return same result if there is no record null in column.
select count(*) from employee
select count(emp_name) from employee
select count(distinct emp_name) from employee
that return the total employee from the employee table,
answer of this 3 query is 100.
but what happen if some records approx 20 of the emp_name is null?
now this 3 query give same answer?
no.
select count(*) from employee
return 100
select count(emp_name) from employee
return 80
select count(distinct emp_name) from employee
return 80
count(*) count the null records while count(column_name) omits the null value so it return 80(100 – 20) record.
hope you are clear with the count(*) count(column_name) and distinct column_name).
thank you.


