Tuesday 25 May 2021

What does count 1 mean in SQL?

 There is a common misunderstanding that it interprets the ordinal of the column.

COUNT(*) takes all columns to count rows which is equivalent to select * from tablename.

COUNT(1) counts using the first column which is the Primary Key which is equivalent to select 1 from tablename, which returns all the records with the value “1” instead of fetching the actual value.

So count(1) little efficient than count(*).

No comments:

Post a Comment