Skip to content

DISTINCT

Ask what values exist without being handed the same one ten times

0 of 3 done · Lesson 3 of 8

Understand

Somebody in marketing asks which channels are sending you signups. There are ten signups and four channels, so selecting the channel column hands them ten rows, most of which say the same thing. The question was about the values, not the rows. DISTINCT throws away the repeats and leaves one of each.

SELECT DISTINCT which_columns_you_want
FROM where_it_lives
WHERE which_rows_to_keep;
SELECTwhich columns you wantDISTINCTdrop the repeatsFROMwhich tableWHEREwhich rows to keep

The tables you are working with

10 rows
First rows of the signups table
idpersonchannelcityplan
1AnasearchAucklandfree
2BosearchWellingtonpro
3CyreferralAucklandfree
4DevsocialDunedinpro

6 more rows in the table. Your query sees all 10.