~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to docs/distinct.rst

having and distinct clauses

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
Distinct
2
 
========
 
 
b'\\ No newline at end of file'
 
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
        SELECT DISTINCT column_name(s)
 
11
        FROM table_name
 
12
 
 
13
**SELECT DISTINCT Example**
 
14
 
 
15
The "Persons" table:
 
16
 
 
17
+---------+------------+----------+----------+--------+
 
18
|Id       |LastName    |FirstName |Address   |  City  |
 
19
+=========+============+==========+==========+========+
 
20
| 1       | Larson     | Sue      |3 Cherry  | Chicago|
 
21
+---------+------------+----------+----------+--------+
 
22
| 2       | Roberts    | Teri     |21 Brown  | Chicago|
 
23
+---------+------------+----------+----------+--------+
 
24
| 3       | Peterson   | Kari     |30 Mell   | Reno   |
 
25
+---------+------------+----------+----------+--------+
 
26
 
 
27
In order to select distinct values from the column named "City" from the table above, use the following SELECT statement: ::
 
28
 
 
29
        SELECT DISTINCT City FROM Persons;
 
30
 
 
31
The result-set will look like this:
 
32
 
 
33
+--------+
 
34
|City    |
 
35
+========+
 
36
|Chicago |
 
37
+--------+
 
38
|Reno    |
 
39
+--------+