Database Reference
In-Depth Information
| 9 | Ben | 2014-08-02 | 79 |
| 10 | Henry | 2014-07-30 | 203 |
+--------+-------+------------+-------+
Many other examples use the
mail
table (used in earlier chapters):
mysql>
SELECT * FROM mail;
+---------------------+---------+---------+---------+---------+---------+
| t | srcuser | srchost | dstuser | dsthost | size |
+---------------------+---------+---------+---------+---------+---------+
| 2014-05-11 10:15:08 | barb | saturn | tricia | mars | 58274 |
| 2014-05-12 12:48:13 | tricia | mars | gene | venus | 194925 |
| 2014-05-12 15:02:49 | phil | mars | phil | saturn | 1048 |
| 2014-05-12 18:59:18 | barb | saturn | tricia | venus | 271 |
| 2014-05-14 09:31:37 | gene | venus | barb | mars | 2291 |
| 2014-05-14 11:52:17 | phil | mars | tricia | saturn | 5781 |
| 2014-05-14 14:42:21 | barb | venus | barb | venus | 98151 |
| 2014-05-14 17:03:01 | tricia | saturn | phil | venus | 2394482 |
| 2014-05-15 07:17:48 | gene | mars | gene | saturn | 3824 |
| 2014-05-15 08:50:57 | phil | venus | phil | venus | 978 |
| 2014-05-15 10:25:52 | gene | mars | tricia | saturn | 998532 |
| 2014-05-15 17:35:31 | gene | saturn | gene | mars | 3856 |
| 2014-05-16 09:00:28 | gene | venus | barb | mars | 613 |
| 2014-05-16 23:04:19 | phil | venus | barb | venus | 10294 |
| 2014-05-19 12:49:23 | phil | mars | tricia | saturn | 873 |
| 2014-05-19 22:21:51 | gene | saturn | gene | venus | 23992 |
+---------------------+---------+---------+---------+---------+---------+
Other tables are used occasionally as well. To create them, use scripts found in the
tables
directory of the
recipes
distribution.
7.1. Using ORDER BY to Sort Query Results
Problem
Rows in a query result don't appear in the order you want.
Solution
Add an
ORDER
BY
clause to the query to sort its result.
Discussion
The contents of the
driver_log
and
mail
tables shown in the chapter introduction are
disorganized and difficult to make sense of. The exception is that the values in the
id
and
t
columns are in order, but that's just coincidental. Rows do tend to be returned
from a table in the order in which they were originally inserted, but only until the table
is subjected to delete and update operations. Rows inserted after that are likely to be
returned in the middle of the result set somewhere. Many MySQL users notice this