SQL Count

SQL Count

The SQL COUNT function returns the number of the rows in a select query.

COUNT syntax

SELECT COUNT(*) FROM table_name;

SELECT COUNT(column_name) FROM table_name;

COUNT example

Coder books table

IDTitlePriceDescription
1Learn SQL20Learn SQL language
2Learn MySQL22Learn MySQL language
3HTML book17Learn HTML
4Learn PHP20Introduction to PHP
5Learn PHP20PHP course
SELECT COUNT(*) 
FROM coder_books;

Result

5

SELECT COUNT(price) 
FROM coder_books 
WHERE price >= 20;

Result

4

SELECT price, COUNT(price) no_count
FROM coder_books
GROUP BY price
HAVING COUNT(*) > 1;

Result

Priceno_count
203