1994.4.16
by Marisa Plumb
new function and clause files, some placeholders for right now |
1 |
Distinct
|
1994.4.17
by Marisa Plumb
having and distinct clauses |
2 |
========
|
3 |
||
4 |
In a table, columns may contain more than one of the same value. |
|
5 |
||
6 |
Sometimes it's helpful to list only the different, distinct values in a table; in this case the DISTINCT keyword can be used. |
|
7 |
||
2165.2.5
by Andrew Hutchings
Make fixes to temporal docs |
8 |
SQL SELECT DISTINCT Syntax: |
9 |
||
10 |
.. code-block:: mysql |
|
1994.4.17
by Marisa Plumb
having and distinct clauses |
11 |
|
12 |
SELECT DISTINCT column_name(s) |
|
13 |
FROM table_name |
|
14 |
||
15 |
**SELECT DISTINCT Example**
|
|
16 |
||
17 |
The "Persons" table: |
|
18 |
||
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 |
+---------+------------+----------+----------+--------+ |
|
28 |
||
2165.2.5
by Andrew Hutchings
Make fixes to temporal docs |
29 |
In order to select distinct values from the column named "City" from the table above, use the following SELECT statement: |
30 |
||
31 |
.. code-block:: mysql |
|
1994.4.17
by Marisa Plumb
having and distinct clauses |
32 |
|
33 |
SELECT DISTINCT City FROM Persons; |
|
34 |
||
35 |
The result-set will look like this: |
|
36 |
||
37 |
+--------+ |
|
38 |
|City | |
|
39 |
+========+ |
|
40 |
|Chicago | |
|
41 |
+--------+ |
|
42 |
|Reno | |
|
43 |
+--------+ |