Best April deals - hours only!Up to 80% off on all courses and bundles.-Close
Ordering
Limiting the output
Eliminating duplicate results
10. 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 employees table in such a way that each year is only shown once.

Stuck? Here's a hint!

Type:

SELECT DISTINCT year
FROM employees;