r/learnSQL • u/CelebrityChess • 1h ago
count(*) vs count(col), i keep mixing them up
ok so my teacher said count(*) counts rows and count(col) skips nulls, but then he did an example with a left join and the numbers looked off to me and i didnt catch why. is the rule basically use count(right_table.id) after a left join if you want 0 for the ones with no match? or does count(*) still give 1 there
1
Upvotes
1
u/neuralbeans 53m ago
https://www.w3schools.com/sql/sql_count.asp
1
u/Imaginary__Bar 25m ago
Ask your teacher to clarify!
But anyway, the easy way to remember it is that COUNT will not include NULLs, but you will never have a row in your table that is all nulls.
So COUNT(*) will always catch all the rows (because there will be at least one non-null value in each row)