~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to docs/orderby.rst

few updates and modifications to admin commands

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
 
.. code-block:: mysql
9
 
 
10
 
        SELECT column_name(s)
11
 
        FROM table_name
12
 
        ORDER BY column_name(s) ASC|DESC;
13
 
 
14
 
**ORDER BY Example**
15
 
 
16
 
The "Persons" table:
17
 
 
18
 
+---------+------------+----------+----------+--------+
19
 
|Id       |LastName    |FirstName |Address   |  City  |
20
 
+=========+============+==========+==========+========+
21
 
| 1       | Larson     | Sue      |3 Cherry  | Chicago|
22
 
+---------+------------+----------+----------+--------+
23
 
| 2       | Roberts    | Teri     |21 Brown  | Chicago|
24
 
+---------+------------+----------+----------+--------+
25
 
| 3       | Peterson   | Kari     |30 Mell   | Reno   |
26
 
+---------+------------+----------+----------+--------+
27
 
 
28
 
To select all the persons from the table above, and also sort them by their last name, use the following SELECT statement:
29
 
 
30
 
.. code-block:: mysql
31
 
 
32
 
        SELECT * FROM Persons
33
 
        ORDER BY LastName;
34
 
 
35
 
The result-set will look like this:
36
 
 
37
 
+---------+------------+----------+----------+--------+
38
 
|Id       |LastName    |FirstName |Address   |  City  |
39
 
+=========+============+==========+==========+========+
40
 
| 1       | Larson     | Sue      |3 Cherry  | Chicago|
41
 
+---------+------------+----------+----------+--------+
42
 
| 3       | Peterson   | Kari     |30 Mell   | Reno   |
43
 
+---------+------------+----------+----------+--------+
44
 
| 2       | Roberts    | Teri     |21 Brown  | Chicago|
45
 
+---------+------------+----------+----------+--------+
46
 
 
47
 
ORDER BY DESC can be used to reverse the order of the result set.
48
 
 
49
 
.. code-block:: mysql
50
 
 
51
 
        SELECT * FROM Persons
52
 
        ORDER BY LastName DESC;
53
 
 
54
 
.. todo::
55
 
 
56
 
   add something about SELECT * without ORDER BY being non-deterministic
57
 
 
58
 
.. todo::
59
 
 
60
 
   add something about how ORDER BY is executed. index scan vs filesort