SQL Fundamentals

DISTINCT & Removing Duplicates: Mistakes

SELECT DISTINCT department, name FROM employees; SELECT DISTINCT department FROM employees; DISTINCT applies to ALL columns. Adding name makes every row unique

SELECT DISTINCT department, name FROM employees;

SELECT DISTINCT department FROM employees;

DISTINCT applies to ALL columns. Adding name makes every row unique because each department+name combination is unique. Only select columns you want to deduplicate on. DISTINCT is not per-column, it's per-row.

DISTINCT is not per-column, it's per-row. All selected columns must match for row to be duplicate.

High

Returns all rows because each department+name combination is unique