Link to home
Create AccountLog in
Avatar of walkerdba

asked on

count *

if we give count(*) what is happening

if we give count(1) what is happening

what is the differecne.
Avatar of David VanZandt
David VanZandt
Flag of United States of America image

I've always known them to be the same for results, the latter looks at the first column for a row, and the wildcard supposedly grabs all columns.  Here's one "definitive" answer:
Avatar of ajexpert
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Good add, aj, that's mentioned in the last paragraph of my reference, but it does help.
However, count(*) was always defined to be the most simple and best performing way of getting a count. Oracle did just ignore that fact for a long time (pre 8i). But it does not matter at all since (at least) 8i.
There can be negative effects for count(1) on other SQL DBMS, if they are not especially ignoring and converting that expression to count(*).

Baseline: count(*) is what you should use.
Avatar of walkerdba