Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Ordering
Eliminating duplicate results
Aggregation
10. Count the rows
Grouping
HAVING: filtering and ordering groups
Let's practice

Instruction

You already know that your database can do computation because we've already added or subtracted values in our SQL instructions. The database can do much more than that. It can compute statistics for multiple rows. This operation is called aggregation.

Let's start with something simple:

SELECT COUNT(*)
FROM orders;

Instead of the asterisk (*) which basically means 'all', we've put the expression COUNT(*).
COUNT(*) is a function. A function in SQL always has a name followed by parentheses. In the parentheses, you can put information which the function needs to work. For example, COUNT() calculates the number of rows specified in the parentheses.

In this case, we've used COUNT(*) which basically means 'count all rows'. As a result, we'll just get the number of all rows in the table orders – and not their content.

Exercise

Count all rows in the table employees.

Stuck? Here's a hint!

Type:

SELECT COUNT(*)
FROM employees;