COUNT
all rows SQL-L047Use consistent syntax to express “count number of rows”.
COUNT(*)
, COUNT(1)
, and even COUNT(0)
are equivalent
syntaxes in many SQL engines due to optimizers interpreting
these instructions as “count number of rows in result”.
The ANSI-92 spec mentions the COUNT(*)
syntax specifically
as having a special meaning:
If
COUNT(*)
is specified, then the result is the cardinality of T.
SELECT
count(1)
FROM table_a
SELECT
count(*)
FROM table_a