Back to DATA RETRIEVAL & FILTERING

SELECT DISTINCT

Understand `DISTINCT` Clause

2 minutesVideo LessonPDF notes
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.

Ready to continue?

Mark this lesson as complete when you're ready to proceed.

Key moments

  1. Introduction and AnalogyThe SELECT DISTINCT statement is introduced using the analogy of sorting unique crayon colors.
  2. Use Case ExampleThe need for DISTINCT is demonstrated using the customers table and the country column to list unique origins.
  3. Basic Syntax and QueryThe standard syntax SELECT DISTINCT column FROM table is shown using the country column example.
  4. Result ComparisonThe difference between a standard SELECT and one using DISTINCT is explained, highlighting the filtering of duplicates.
  5. Counting Unique ValuesThe COUNT(DISTINCT column) function is introduced as the method for calculating the number of unique entries.
  6. MS Access WorkaroundA subquery technique is provided as a trick to count distinct values in SQL environments that do not support COUNT(DISTINCT).
  7. ConclusionThe lesson concludes by summarizing that SELECT DISTINCT is essential for viewing only unique data.
PDF notes

Frequently asked questions

Does DISTINCT work if I select more than one column?

Yes, but it returns unique combinations of all selected columns. A row is only considered a duplicate if every column matches another row exactly.

Why would I use DISTINCT instead of just grouping the results?

DISTINCT is simpler and faster when you only need the unique list itself, not aggregate calculations associated with those groups.

Is COUNT(DISTINCT) standard across all SQL databases?

Most modern databases support it, but older systems like MS Access require using a subquery to achieve the same result.