🔧 Quick Syntax
SELECT COUNT(column_name)
FROM table_name;
This is how you ask SQL:
“How many rows have something in this column?”
🧾 Here’s the Table You’re Working With
Your table is called orders
:
order_id | customer_name | total_amount |
---|---|---|
1 | Fenn Rask | 10.00 |
2 | Milo Kresh | 45.00 |
3 | Sora Dune | 15.99 |
4 | Lexa Vohn | 72.50 |
5 | Tovi Glint | 29.99 |
✅ Suppose You Want to Know How Many Orders There Are
SELECT COUNT(*) FROM orders;
💡 Output:
5
COUNT(*)
means “count all rows” — including ones with NULL
values.
✅ Suppose You Only Want to Count Rows with a Total Amount
SELECT COUNT(total_amount)
FROM orders;
💡 Output:
5
This only counts rows where total_amount
is NOT NULL.
If any rows had NULL, they’d be skipped.
✅ Suppose You Want to Count Unique Customer Names
SELECT COUNT(DISTINCT customer_name)
FROM orders;
💡 Output:
5
This gives you the number of different customer names. If someone ordered twice, they’re only counted once.
🧃 Recap – What You Learned
COUNT(*)
= count all rows (even with NULLs)COUNT(column)
= count only non-NULL valuesCOUNT(DISTINCT column)
= count unique values- Great for totals, stats, analytics, and dashboards