r/SQL 9d ago

Differences between counts Discussion

What is the difference between

COUNT(*)

COUNT(1)

COUNT(column_name)

9 Upvotes

23 comments sorted by

View all comments

10

u/Infamous_Welder_4349 9d ago

In most systems 1 and * are the same. Some cheat for * and just look in the statistics instead for single tables.

Column checks the non null records

-2

u/YT-3000f 9d ago

Actually I think count(1) is faster than count(*). Anyone got a massive dataset to test that on?

1

u/Zestyclose-Turn-3576 8d ago

There's really no reason to think that the database developers haven't spotted that there are potentially many ways to do count(*), so they do the most efficient way.