Sort Rows
- It is easier to examine query output when the rows are sorted in some meaningful way.
- To sort a result, use an
ORDER BY clause.
- For example:
mysql> SELECT * FROM pet ORDER BY age;
- For numeric values, the default sort order is ascending, with smallest values first.
- To sort in reverse (descending) order, add the
DESC keyword to the name of the column.
- For example:
mysql> SELECT * FROM pet ORDER BY age DESC;
- On character type columns, sorting is normally performed in a case-insensitive fashion.
- Force a case-sensitive sort for a column by using
BINARY.
- For example:
mysql> SELECT * FROM pet ORDER BY BINARY owner;
How does MySQL handle date calculations?
© 2007 John Michael Pierobon
Notes