Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Ordering
Limiting the output
Eliminating duplicate results
Aggregation
14. Count distinct values in a column
Grouping
HAVING: filtering and ordering groups
Let's practice

Instruction

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

SELECT
  COUNT(DISTINCT CustomerId) AS DistinctCustomer
FROM Order;

This time, we count the number of unique CustomerIds. In other words, this instruction tells us how many different customers have placed an order so far. If a customer places five orders, the customer will only be counted once.

Exercise

Count how many different positions there are in the Employee table. Name the column DistinctPositions.

Stuck? Here's a hint!

Type:

SELECT
  COUNT(DISTINCT Position) AS DistinctPositions
FROM Employee;