TL;DR: Use COUNT(*), not COUNT(id), when you want to count rows. You have probably read in a bunch of different places that you shouldn't use SELECT(*) in MySQL when you don't need all the data.

While SELECT(*) selects all the columns, COUNT(*) is specifically optimized to count all the rows.

If a secondary index is not present, InnoDB processes SELECT COUNT(*) statements by scanning the clustered index.

It contains the indexed data and a pointer to the primary key (clustered index) where you can get the rest of the data.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners