We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Best Way to Count the Total Number of Rows in a Table: COUNT(*) vs. COUNT(1)
Summary
Description
If you need to count the total number of rows in a relational table, the COUNT() function often comes to mind first. However, if you search online, you'll come across many resources suggesting that COUNT(1) is more efficient. So, should we use COUNT(), COUNT(1), or even COUNT(id)?
In this video, you'll learn which version of the COUNT function is the most efficient by reviewing how the function works, comparing execution plans, and analyzing latencies across four major databases: PostgreSQL, Oracle, MySQL, and SQL Server.
0:00 COUNT(*) vs. COUNT(1) dilemma
0:40 PostgreSQL, comparing execution plans
4:30 PostgreSQL, comparing latencies
5:32 Oracle, comparing execution plans
7:30 Oracle, comparing latencies
8:25 MySQL, comparing execution plans
9:20 MySQL, comparing latencies
10:50 SQL Server, comparing execution plans
12:52 SQL Server, comparing latencies
13:17 When does an index make things faster?
Curios to learn even more about databases, follow me here:
* Medium: https://medium.com/@magda7817
* X (Twitter): https://twitter.com/denismagda
Translated At: 2025-06-29T14:40:38Z