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
| id | person | channel | city | plan |
|---|---|---|---|---|
| 1 | Ana | search | Auckland | free |
| 2 | Bo | search | Wellington | pro |
| 3 | Cy | referral | Auckland | free |
| 4 | Dev | social | Dunedin | pro |
6 more rows in the table. Your query sees all 10.