Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Ordering
Eliminating duplicate results
8. Select distinctive 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 is shown many times in the results.

In our orders example, if there were many orders placed by the same customer, each customer id would be shown many times in the results. Not good.

Fortunately, we can easily change this.

SELECT DISTINCT customer_id
FROM orders;

Before the column name, we've added the word DISTINCT. Now the database will remove duplicates and only show distinct values. Each customer_id will appear only once.

Exercise

Select the column year from the table employees in such a way that each year is only shown once.

Stuck? Here's a hint!

Type:

SELECT DISTINCT year
FROM employees;