0Pricing
SQL Interview Prep · Lesson

DISTINCT vs GROUP BY for Uniqueness

When DISTINCT is the right answer and when an interviewer expects GROUP BY instead.

What DISTINCT Does

DISTINCT removes duplicate rows. The key thing interviewers check: it works on the whole selected row, not one column — so SELECT DISTINCT a, b dedupes the pair (a, b).

SELECT DISTINCT department
FROM employees;

DISTINCT Spans All Selected Columns

With several columns, DISTINCT keeps each unique combination — one row per distinct (department, job_title) pair. There's no standard way to dedupe just one column.

SELECT DISTINCT department, job_title
FROM employees;

All lessons in this course

  1. Projecting Columns and Aliasing Pitfalls
  2. Computed Columns and Expression Precedence
  3. DISTINCT vs GROUP BY for Uniqueness
  4. CASE Expressions in SELECT
← Back to SQL Interview Prep