Difference between count(*) and count(1) in mysql?

WePython 1 Months+

In MySql we can count the total number of records by using count(1) or count(*).

Is there any technical difference between them?


They are the same. This has often been asked in Stackoverflow and here

count(*), count(0), count(1), count(-1)

all return the count.

Edit In fact, in SQL Server, a COUNT(ALL ...) CONSTANT expression doesn't appear to be evaluated at all, however, a COUNT(DISTINCT ...) is*.


select count(ALL 1/0) from xyz; -- Succeeds


select count(DISTINCT 1/0) from xyz;  -- Divide by Zero

and at least one exception is NULL

select count(1) from xyz; -- Operand data type void type is invalid for count operator.

FWR in MySQL count(1/0) returns 0 irrespective of the number of rows.

Previous : Optimizing my update sequence
Next : how to query for rows by specifying the range of row numbers in postgresql