SQL COUNT

COUNT function returns the number of rows in the query.

NULL values are not counted.

COUNT SQL syntax:

SELECT COUNT (column) FROM table

To get the number of rows in a table

SELECT COUNT(*) FROM tabla

To get the number of distinct values ??of the specified column.

SELECT COUNT(DISTINCT column) FROM table.

Examples of SQL COUNT:

Given the following table 'orders'

idorderclientprice
1p1HARRY100
2p2CLARK300
3p3SMITH250
4p4BROWN490
5p5WHITE60
SELECT COUNT(*) FROM orders

Returns the number of rows in the table, ie 5

SELECT COUNT(*) FROM orders WHERE client = ‘HARRY’

Returns the number of rows in the query result, ie 1

SELECT COUNT(*) FROM orders WHERE price > 270

Returns the number of rows in the query result, ie 2