On this page
  1. COUNT
  2. Syntax & Overview
  3. Notes & Best Practices
  4. Example

COUNT

Prev: functions | Up: functions | Next: `SUM`
Rel: functions, Aggregations, CTEs & Window Functions
Ref: PostgreSQL — SQL Commands
Tags: #public #databases #sql #functions #tier/core


Syntax & Overview

COUNT(*)  |  COUNT(DISTINCT user_id)

Counts rows (COUNT(*)) or non-null values (COUNT(col)).

Notes & Best Practices

Example

SELECT COUNT(*) AS total_rows, COUNT(email) AS with_email
FROM users;

Linked from

Related notes