SQL TutorialLesson 18Free preview
SQL Count()
This lesson is part of SQL · All levels
Summary
The COUNT function calculates the number of rows or the number of non-NULL values in a column. COUNT(*) counts all rows regardless of NULL, whereas COUNT(column) ignores the row with the value NULL on the column. COUNT can also be used with DISTINCT to calculate the number of unique values.
Key points
- COUNT(*) counts the entire row in the table or the result of the join.
- COUNT(column) counts the row whose column is not NULL.
- COUNT(DISTINCT column) calculates the number of unique values.
- Count without GROUP BY produces a single row of summaries.
- COUNT can also calculate the results of expressions, for example COUNT(price * 2).
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.