In SQL, what's the difference between count(column) and count(*)? -


i have following query:

select column_name, count(column_name) table group column_name having count(column_name) > 1; 

what difference if replaced calls count(column_name) count(*)?

this question inspired how find duplicate values in table in oracle?.


to clarify accepted answer (and maybe question), replacing count(column_name) count(*) return row in result contains null , count of null values in column.

count(*) counts nulls , count(column) not

[edit] added code people can run it

create table #bla(id int,id2 int) insert #bla values(null,null) insert #bla values(1,null) insert #bla values(null,1) insert #bla values(1,null) insert #bla values(null,1) insert #bla values(1,null) insert #bla values(null,null)  select count(*),count(id),count(id2) #bla 

results 7 3 2


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -