~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to docs/distinct.rst

doc modifications

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Distinct
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
 
 
8
 
SQL SELECT DISTINCT Syntax: 
9
 
 
10
 
.. code-block:: mysql
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
 
 
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
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
 
+--------+