4
In a table, columns may contain more than one of the same value.
6
Sometimes it's helpful to list only the different, distinct values in a table; in this case the DISTINCT keyword can be used.
8
SQL SELECT DISTINCT Syntax:
12
SELECT DISTINCT column_name(s)
15
**SELECT DISTINCT Example**
19
+---------+------------+----------+----------+--------+
20
|Id |LastName |FirstName |Address | City |
21
+=========+============+==========+==========+========+
22
| 1 | Larson | Sue |3 Cherry | Chicago|
23
+---------+------------+----------+----------+--------+
24
| 2 | Roberts | Teri |21 Brown | Chicago|
25
+---------+------------+----------+----------+--------+
26
| 3 | Peterson | Kari |30 Mell | Reno |
27
+---------+------------+----------+----------+--------+
29
In order to select distinct values from the column named "City" from the table above, use the following SELECT statement:
33
SELECT DISTINCT City FROM Persons;
35
The result-set will look like this: