<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/stop-using-count-id-to-count-rows-vlrnmqlzw" -->

---
title: Stop using COUNT(id) to count rows | daily.dev
description: Counting rows using COUNT(*) in MySQL is not slow as often believed. It is actually optimized to be the fastest way to count rows.
canonical: https://daily.dev/posts/stop-using-count-id-to-count-rows-vlrnmqlzw
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Stop using COUNT(id) to count rows | daily.dev
og:description: Counting rows using COUNT(*) in MySQL is not slow as often believed. It is actually optimized to be the fastest way to count rows.
og:url: https://daily.dev/posts/stop-using-count-id-to-count-rows-vlrnmqlzw
og:image: https://api.daily.dev/og/posts/vLRnMqLZW.png
og:image:alt: Stop using COUNT(id) to count rows
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Stop using COUNT(id) to count rows

**[Community Picks](https://daily.dev/sources/community)** · 7 min read · 790 upvotes · 27 comments

## Summary

Counting rows using COUNT(*) in MySQL is not slow as often believed. It is actually optimized to be the fastest way to count rows.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.youtube.com/watch?v=H6juZ8c_Nu8>

## Community discussion

Top comments from developers on daily.dev.

**@includenull** · 14 upvotes

> Super informative video, it's a shame PlanetScale let Aaron go as part of their layoffs, but I get it. I think Aaron will be just fine and he has his own YouTube channel too!

**@kripi\_png** · 7 upvotes

> So this video is about MySQL. Does it work the same way in PostgreSQL or SQLite, for example?

**@ivansuknovic** · 3 upvotes

> Kudos for debunking the myth

**@teec** · 3 upvotes

> This is a very good video. I've been working with SQL Server for over 15 years now and always heard don't use Count(*).  I know that the user was using MySql but I'm assuming this logic flows over to Sql Server as well. Now I know in SQL Server if you do COUNT(column_name) and the value is NULL then it doesn't count that column. I think I'm going back to Count(*) .  :)

**@jakecake** · 3 upvotes

> Great video, but why are we even given this argument if the optimizer always replaces it? In what case would you give a column name to `count`?

## Similar posts on daily.dev

- [Don’t just attend KubeCon \+ CloudNativeCon, Merge Forward your experience\!](https://daily.dev/posts/don-t-just-attend-kubecon-cloudnativecon-merge-forward-your-experience--l0rpp73x8) · CNCF · 1 upvotes · 0 comments
- [Announcing H2 2026 KCDs](https://daily.dev/posts/announcing-h2-2026-kcds-m96goajm1) · CNCF · 1 upvotes · 0 comments
- [Two months of Open Community Groups](https://daily.dev/posts/two-months-of-open-community-groups-asf52zhbs) · CNCF · 0 upvotes · 0 comments
- [CNCF Unveils Schedule for KubeCon \+ CloudNativeCon Europe 2026](https://daily.dev/posts/cncf-unveils-schedule-for-kubecon-cloudnativecon-europe-2026-ikhcoa5cb) · CNCF · 2 upvotes · 0 comments
- [CNCF Debuts KubeCon \+ CloudNativeCon Japan 2026 Schedule](https://daily.dev/posts/cncf-debuts-kubecon-cloudnativecon-japan-2026-schedule-xp5pyudub) · CNCF · 1 upvotes · 0 comments

---

Tags: [#database](https://daily.dev/tags/database), [#mysql](https://daily.dev/tags/mysql), [#performance](https://daily.dev/tags/performance), [#sql](https://daily.dev/tags/sql)

[View this post on daily.dev](https://daily.dev/posts/stop-using-count-id-to-count-rows-vlrnmqlzw)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Stop using COUNT(id) to count rows","url":"https://daily.dev/posts/stop-using-count-id-to-count-rows-vlrnmqlzw","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/stop-using-count-id-to-count-rows-vlrnmqlzw"},"datePublished":"2024-03-08T03:37:00.182Z","dateModified":"2024-04-11T02:13:33.708Z","description":"Counting rows using COUNT(*) in MySQL is not slow as often believed. It is actually optimized to be the fastest way to count rows.","image":"https://i.ytimg.com/vi/H6juZ8c_Nu8/sddefault.jpg","thumbnailUrl":"https://i.ytimg.com/vi/H6juZ8c_Nu8/sddefault.jpg","isAccessibleForFree":true,"articleSection":"Community Picks","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Community Picks","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1655817725/logos/community","url":"https://daily.dev/sources/community"},"commentCount":27,"discussionUrl":"https://daily.dev/posts/stop-using-count-id-to-count-rows-vlrnmqlzw","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":790},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":27}],"keywords":"database,mysql,performance,sql","timeRequired":"PT7M","video":{"@type":"VideoObject","name":"Stop using COUNT(id) to count rows","description":"Counting rows using COUNT(*) in MySQL is not slow as often believed. It is actually optimized to be the fastest way to count rows.","thumbnailUrl":"https://i.ytimg.com/vi/H6juZ8c_Nu8/sddefault.jpg","uploadDate":"2024-03-08T03:37:00.182Z","duration":"PT7M","url":"https://api.daily.dev/r/vLRnMqLZW","embedUrl":"https://www.youtube.com/embed/H6juZ8c_Nu8"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Community Picks","item":"https://daily.dev/sources/community"},{"@type":"ListItem","position":3,"name":"Stop using COUNT(id) to count rows"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/stop-using-count-id-to-count-rows-vlrnmqlzw","comment":[{"@type":"Comment","text":"Super informative video, it’s a shame PlanetScale let Aaron go as part of their layoffs, but I get it. I think Aaron will be just fine and he has his own YouTube channel too!","datePublished":"2024-03-08T11:01:50.831Z","url":"https://daily.dev/posts/vLRnMqLZW#c-VHJbihodx","author":{"@type":"Person","name":"includenull","url":"https://daily.dev/includenull","image":"https://avatars0.githubusercontent.com/u/15929809?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":14}},{"@type":"Comment","text":"So this video is about MySQL. Does it work the same way in PostgreSQL or SQLite, for example?","datePublished":"2024-03-09T09:18:24.453Z","url":"https://daily.dev/posts/vLRnMqLZW#c-alNwEukvI","author":{"@type":"Person","name":"kripi","url":"https://daily.dev/kripi_png","image":"https://avatars.githubusercontent.com/u/66375160?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":7}},{"@type":"Comment","text":"Kudos for debunking the myth","datePublished":"2024-03-08T14:19:41.686Z","url":"https://daily.dev/posts/vLRnMqLZW#c-LorCq8CDB","author":{"@type":"Person","name":"Ivan Suknovic","url":"https://daily.dev/ivansuknovic","image":"https://media.daily.dev/image/upload/s--O0TOmw4y--/f_auto/v1715772965/public/noProfile"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3}},{"@type":"Comment","text":"This is a very good video. I’ve been working with SQL Server for over 15 years now and always heard don’t use Count().  I know that the user was using MySql but I’m assuming this logic flows over to Sql Server as well. Now I know in SQL Server if you do COUNT(column_name) and the value is NULL then it doesn’t count that column. I think I’m going back to Count() .  :)","datePublished":"2024-03-11T12:54:08.176Z","dateModified":"2024-03-11T12:56:19.132Z","url":"https://daily.dev/posts/vLRnMqLZW#c-fs5AOUrC1","author":{"@type":"Person","name":"Terrance Copling","url":"https://daily.dev/teec","image":"https://lh3.googleusercontent.com/a/ALm5wu3_Usp-GBLmuz6uPGltJDCRTx3ICuAe39rvPGcz=s100"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3}},{"@type":"Comment","text":"Great video, but why are we even given this argument if the optimizer always replaces it? In what case would you give a column name to count?","datePublished":"2024-03-08T17:14:41.441Z","url":"https://daily.dev/posts/vLRnMqLZW#c-dTyiI3uDV","author":{"@type":"Person","name":"Jacob Kofoed","url":"https://daily.dev/jakecake","image":"https://avatars.githubusercontent.com/u/4046799?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3}}]}
```

