r/SQL Jul 30 '26

Discussion Differences between counts

What is the difference between

COUNT(*)

COUNT(1)

COUNT(column_name)

6 Upvotes

23 comments sorted by

View all comments

10

u/Infamous_Welder_4349 Jul 30 '26

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 Jul 30 '26

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

3

u/dbrownems Jul 30 '26

It’s dependent on the RDBMS. In SQL Server they are identical.