~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to docs/orderby.rst

  • Committer: Lee Bieber
  • Date: 2010-11-14 23:15:42 UTC
  • mfrom: (1929.1.42 warning-stack-frame)
  • Revision ID: kalebral@gmail.com-20101114231542-fnnu6ydd2p17n582
Merge Monty - fix bug 672372: some functions use > 32k stack

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Order By
2
 
========
3
 
 
4
 
The ORDER BY keyword is used to sort the result-set by column; by default, it sorts the records in ascending order.
5
 
 
6
 
SQL ORDER BY Syntax: ::
7
 
 
8
 
        SELECT column_name(s)
9
 
        FROM table_name
10
 
        ORDER BY column_name(s) ASC|DESC;
11
 
 
12
 
**ORDER BY Example**
13
 
 
14
 
The "Persons" table:
15
 
 
16
 
+---------+------------+----------+----------+--------+
17
 
|Id       |LastName    |FirstName |Address   |  City  |
18
 
+=========+============+==========+==========+========+
19
 
| 1       | Larson     | Sue      |3 Cherry  | Chicago|
20
 
+---------+------------+----------+----------+--------+
21
 
| 2       | Roberts    | Teri     |21 Brown  | Chicago|
22
 
+---------+------------+----------+----------+--------+
23
 
| 3       | Peterson   | Kari     |30 Mell   | Reno   |
24
 
+---------+------------+----------+----------+--------+
25
 
 
26
 
To select all the persons from the table above, and also sort them by their last name, use the following SELECT statement: ::
27
 
 
28
 
        SELECT * FROM Persons
29
 
        ORDER BY LastName;
30
 
 
31
 
The result-set will look like this:
32
 
 
33
 
+---------+------------+----------+----------+--------+
34
 
|Id       |LastName    |FirstName |Address   |  City  |
35
 
+=========+============+==========+==========+========+
36
 
| 1       | Larson     | Sue      |3 Cherry  | Chicago|
37
 
+---------+------------+----------+----------+--------+
38
 
| 3       | Peterson   | Kari     |30 Mell   | Reno   |
39
 
+---------+------------+----------+----------+--------+
40
 
| 2       | Roberts    | Teri     |21 Brown  | Chicago|
41
 
+---------+------------+----------+----------+--------+
42
 
 
43
 
ORDER BY DESC can be used to reverse the order of the result set. ::
44
 
 
45
 
        SELECT * FROM Persons
46
 
        ORDER BY LastName DESC;
47
 
 
48
 
FIXME: add something about SELECT * without ORDER BY being non-deterministic
49
 
 
50
 
FIXME: add something about how ORDER BY is executed. index scan vs filesort