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

Instruction

Could you see the problem? There were many rows with the same year, so each year appeared many times in the result set.

In our orders example, if there were many orders placed by the same customer, each customer ID would appear many times in the result set. Not good!

Fortunately, we can easily this change behavior:

SELECT DISTINCT
  CustomerId
FROM Order;

Before the column names, we've added the DISTINCT keyword. Now, the database will remove duplicates and only show distinct values. Each CustomerId will appear only once.

Exercise

Select the Year column from the Employee table such that each year is only shown once.

Stuck? Here's a hint!

Type:

SELECT DISTINCT
  Year
FROM Employee;