Problems / Remove Duplicates / Editorial
The key insight is that duplicates share the same customer_name, product, quantity, and order_date. By grouping on these columns and taking MIN(order_id), we keep only the first occurrence.
customer_name
product
quantity
order_date
MIN(order_id)
```sql
SELECT MIN(order_id) AS order_id, customer_name, product, quantity, order_date
FROM orders
GROUP BY customer_name, product, quantity, order_date
```
An alternative approach uses ROW_NUMBER() with a window function, but the GROUP BY approach is simpler for this case since we only need the minimum order_id.
ROW_NUMBER()
GROUP BY
order_id
Solve Remove Duplicates yourself →