PostgreSQL SyntaxLesson 23Free preview
PostgreSQL COUNT
This lesson is part of PostgreSQL · All levels
Summary
COUNT is an aggregate function for calculating the number of rows or the number of values in a column. The COUNT(*) variants count all rows, whereas COUNT(column) only counts values that are not NULL. Plus DISTINCT, you can calculate how many unique values there are on that column.
Key points
- COUNT(*) counts the entire row including the value of NULL.
- COUNT(column) only counts the non-NULL value on that column.
- COUNT(DISTINCT column) calculates the number of unique values.
- It is often used together with GROUP BY for group statistics.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.