HomeInterview QuestionsCould you explain the difference between COUNT(*) …

Could you explain the difference between COUNT(*) and COUNT(1)?

🟢 Easy Conceptual Junior level
1Times asked
May 2026Last seen
May 2026First seen

💡 Model Answer

COUNT() counts the number of rows in a result set, regardless of NULL values, because it counts the rows themselves. COUNT(1) evaluates the constant expression 1 for each row; since 1 is never NULL, it also counts every row. In practice, most SQL engines treat COUNT() and COUNT(1) the same and optimize them to identical execution plans, so performance is identical. Historically, COUNT() was considered faster because it didn’t need to evaluate a column expression, but modern query optimizers eliminate that difference. The real distinction appears when you use COUNT(column), which counts only non‑NULL values of that column. Example: SELECT COUNT() FROM orders; and SELECT COUNT(1) FROM orders; both return the total number of rows in the orders table. Use COUNT(*) for clarity when you want to count all rows, and use COUNT(column) when you need to exclude NULLs.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers — invisible to screen sharing.

Get Assisting AI — Starts at ₹500