Ordering
Limiting the output
Eliminating duplicate results
9. Duplicate results
Aggregation
Grouping
HAVING: filtering and ordering groups
Let's practice

Instruction

Very good! We'll now focus on another topic. By default, the database returns every row that matches the given criteria. This isn't always ideal, especially when it comes to duplicate rows.

Imagine the following situation: we want to get the IDs of all customers who have ever placed an order. We might use the following code:

SELECT
  CustomerId
FROM Order;

What's wrong with the code in this case? Well, try to do the exercise to find out.

Exercise

Select the Year column for all rows in the Employee table. Then, examine the result carefully.

Stuck? Here's a hint!

Type:

SELECT
  Year
FROM Employee;