The clause removes duplicates and filters unique values.
Structure:
SELECT DISTINCT column_name FROM table_name;
Example1:
We have a table Customer with this data:
CustomerID | Name | Hair | Salary |
---|---|---|---|
1 | Alechandro | brown | 100 |
2 | Katerina | blonde | 150 |
3 | Lucie | blonde | 30 |
4 | Thomas | black | 40 |
5 | Theodor | black | 120 |
6 | Thomassino | black | 99 |
7 | Knor | brown | 50 |
8 | Thor | blonde | 10 |
9 | Lucie | pink | 70 |
We will choose a blonde color without the DISTINCT clause.
SELECT name FROM Customer;
NAME |
---|
Alechandro |
Katerina |
Lucie |
Thomas |
Theodor |
Thomassino |
Knor |
Thor |
Lucie |
Example2:
Similar SELECT with DISTINCT:
SELECT DISTINCT name FROM Customer;
NAME |
---|
Thomas |
Knor |
Katerina |
Thor |
Lucie |
Thomassino |
Alechandro |
Theodor |
I give people clear, functional, and proven instructions. I gently guide them so that they can fulfill their IT dreams.