|
|
Ordering the Result Table
Strictly, the order of rows in a result table is undefined unless an
ORDER BYclause is included in theSELECTstatement.Ascending or descending order may be specified; ascending order is the default.
Note: A SELECT statement without an ORDER BY clause may appear to give an ordered result in Mimer SQL, but you should include an ORDER BY clause if the ordering is important. Without the ORDER BY clause, a change in the database contents or updated Mimer SQL version can otherwise change the order.
Example
SELECT * FROM formats ORDER BY format DESC;Returns:
FORMAT Vinyl Video Paperback Hardcover DVD Video DVD Audio Cassette Audio CD Audio CD Audio CassetteOrdering by More than One Column
More than one column may be specified in the
ORDER BYclause.Example:
SELECT * FROM formats ORDER BY category_id, display_order;Returns:
FORMAT DVD Audio Audio CD Cassette Vinyl Hardcover Paperback Audio CD Audio Cassette DVD Video VideoOrdering by Set Function
To order a result table by a set function, the column in the result table is given a label and the label is used in the
ORDER BYclause.Example:
SELECT category_id, MAX(display_order) AS maximum_value FROM formats GROUP BY category_id ORDER BY maximum_value;Returns:
Ordering by a Computed Value
To order a result table by a computed value, place the computation in the
ORDER BYclause.Example:
SELECT product FROM products JOIN items ON products.product_id = items.product_id WHERE format_id = 2 ORDER BY stock * price;Returns:
|
Mimer Information Technology AB Voice: +46 18 780 92 00 Fax: +46 18 780 92 40 info@mimer.se |
|
|