COUNT() – Count How Many Rows in SQL

🔧 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
1Fenn Rask10.00
2Milo Kresh45.00
3Sora Dune15.99
4Lexa Vohn72.50
5Tovi Glint29.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 values
  • COUNT(DISTINCT column) = count unique values
  • Great for totals, stats, analytics, and dashboards

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top