COUNT(column) vs COUNT(*) in SQL — With INNER, LEFT, RIGHT & FULL JOIN Explained
📰 Dev.to · Tim Nguyen
Learn the difference between COUNT(column) and COUNT(*) in SQL when using INNER, LEFT, RIGHT, and FULL JOIN to avoid common bugs
Action Steps
- Use COUNT(column) to count non-NULL values in a specific column
- Use COUNT(*) to count all rows in a result set, including NULL values
- Apply INNER JOIN to count matching rows between two tables
- Apply LEFT JOIN to count all rows from the left table and matching rows from the right table
- Apply RIGHT JOIN and FULL JOIN to understand how COUNT(column) and COUNT(*) behave with different join types
Who Needs to Know This
Database administrators, data analysts, and backend developers can benefit from understanding the nuances of COUNT(column) and COUNT(*) in SQL joins to write more accurate queries
Key Insight
💡 COUNT(column) only counts non-NULL values, while COUNT(*) counts all rows, including NULL values
Share This
📊 COUNT(column) vs COUNT(*) in SQL: know the difference to avoid bugs in your joins!
Key Takeaways
Learn the difference between COUNT(column) and COUNT(*) in SQL when using INNER, LEFT, RIGHT, and FULL JOIN to avoid common bugs
Full Article
Counting seems simple in SQL… until joins enter the picture. One of the most common bugs...
DeepCamp AI