Counting Rows with COUNT
COUNT is an aggregate function that counts rows. It's one of the most commonly used functions in SQL.
COUNT Syntax
-- Count all rows
SELECT COUNT(*) FROM table_name;
-- Count non-NULL values in a column
SELECT COUNT(column_name) FROM table_name;
New Tables Available
Starting from this lesson, you have access to more tables:
- users - User accounts
- categories - Product categories
- products - Products with prices and stock
Explore the schema panel on the left to see all columns!
Exercises
Loading exercise...
Loading exercise...
Loading exercise...
Loading exercise...
Loading exercise...
COUNT(*) vs COUNT(column)
COUNT(*)counts all rows, including those with NULL valuesCOUNT(column)counts only non-NULL values in that column
Free Practice
Loading SQL editor...
Try:
- Count products in different categories
- Count products within a price range
- Count products with stock below a threshold

