Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Eliminating duplicate results
12. Count distinctive values in a column
HAVING: filtering and ordering groups
Let's practice


Great. As you probably expect, we can also add the keyword DISTINCT in our function COUNT():

SELECT COUNT(DISTINCT customer_id) AS distinct_customers
FROM orders;

This time, we count all rows which have a distinctive value in the column customer_id. In other words, this instruction tells us how many different customers have placed an order so far. If a customer places 5 orders, the customer will only be counted once.


Count how many different positions there are in the table employees. Name the column distinct_positions.

Stuck? Here's a hint!


SELECT COUNT(DISTINCT position) AS distinct_positions
FROM employees;