SQL

Counting Rows

The COUNT Function

COUNT() counts the number of rows. It's one of the most commonly used aggregate functions — functions that summarize multiple rows into a single value.

Syntax

-- Count ALL rows in a table
SELECT COUNT(*) FROM table_name;

-- Count non-NULL values in a specific column SELECT COUNT(column_name) FROM table_name;

What's the difference?

FunctionWhat it counts
<code>COUNT(*)</code>ALL rows, including NULLs
<code>COUNT(email)</code>Only rows where email is NOT NULL

Examples

-- How many products do we have?
SELECT COUNT(*) FROM products;

-- How many products have a category? SELECT COUNT(category) FROM products;

-- Count can be combined with WHERE SELECT COUNT(*) FROM products WHERE price > 50;

💡 Real-World Use

"How many customers do we have?" — SELECT COUNT(*) FROM customers; "How many orders were placed today?" — SELECT COUNT(*) FROM orders WHERE order_date = '2026-02-08';

Your Task

Count the total number of products in the products table.

query.sql
Loading SQL engine...
Downloading SQL engine… (one-time)

Downloading SQL engine… (one-time)

This runs entirely in your browser and is cached for next time.