"Fossies" - the Fresh Open Source Software Archive

Member "drizzle-7.1.36-stable/docs/orderby.rst" (6 May 2012, 1896 Bytes) of package /linux/misc/old/drizzle-7.1.36-stable.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format (assuming markdown format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.

ORDER BY

The ORDER BY keyword is used to sort the result-set by column; by default, it sorts the records in ascending order.

SQL ORDER BY Syntax:

SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC;

ORDER BY Example

The "Persons" table:

Id LastName FirstName Address City
1 Larson Sue 3 Cherry Chicago
2 Roberts Teri 21 Brown Chicago
3 Peterson Kari 30 Mell Reno

To select all the persons from the table above, and also sort them by their last name, use the following SELECT statement:

SELECT * FROM Persons
ORDER BY LastName;

The result-set will look like this:

Id LastName FirstName Address City
1 Larson Sue 3 Cherry Chicago
3 Peterson Kari 30 Mell Reno
2 Roberts Teri 21 Brown Chicago

Without using "ORDERBY" in the following query, the result-set will be non-deterministic, and could returned matching rows in a different order for each query.

ORDER BY DESC can be used to reverse the order of the result set.

SELECT * FROM Persons
ORDER BY LastName DESC;

add something about how ORDER BY is executed. index scan vs filesort