ORDER BY Clause¶
ORDER BY clause sorts the data returned by a query, by the
specified column list.
<order by> ::=
ORDER BY <order by expression> [ ASC | DESC ]
[, <order by expression> [ ASC | DESC ] ]*
<order by expression> ::=
| <field position:integer>
Usually, Virtual DataPort processes the data obtained from the sources
asynchronously. I.e. it can begin sending results to clients without
having to wait to process all the data obtained from the sources.
However, if the query uses
ORDER BY and this cannot be pushed down
to the source, the result of the query is generated synchronously. I.e.
the results are not available until all the data from the sources has
ORDER BY clause of a query you can indicate:
A name of a field or the alias of a field projected by the query (i.e. in the
SELECTclause of the query).
An expression based on the name of the fields or aliases of the projected fields.
The position of the fields in the
SELECTclause by which you want to sort the result.
DESC modifiers are optional. If missing, the results
are sorted in an ascending order.
The following query obtains the employees ordered according to the
pay in a descending order.
ORDER BY pay DESC;
In the following query, the order by field is indicated with its
position in the
SELECT name, pay
ORDER BY 2 DESC;
The index of the first field is 1.
The following query uses an expression in the
ORDER BY clause:
ORDER BY lower(summary)