Index: pages/lang.in ================================================================== --- pages/lang.in +++ pages/lang.in @@ -3900,17 +3900,23 @@ simple SELECT statements, (A op B op C) is processed as ((A op B) op C).)^

hd_fragment orderby {order by} -

+

### ORDER BY clauses

If a SELECT statement that returns more than one row does not have an ORDER BY clause, the order in which the rows are returned is undefined. Or, if a SELECT statement does have an ORDER BY clause, then the list of expressions attached to the ORDER BY determine the order in which rows -are returned to the user. ^Rows are first sorted based on the results of +are returned to the user. +In a compound SELECT statement, only the last (right-most) SELECT may have +an ORDER BY clause and that ORDER BY clause will apply across all elements of +the compound. + + +

^Rows are first sorted based on the results of evaluating the left-most expression in the ORDER BY list, then ties are broken by evaluating the second left-most expression and so on. The order in which two rows for which all ORDER BY expressions evaluate to equal values are returned is undefined. ^Each ORDER BY expression may be optionally followed by one of the keywords ASC (smaller values are returned first) or DESC (larger @@ -3963,13 +3969,20 @@ matched against. Otherwise, the next SELECT to the right is tried, and so on.)^ ^If no matching expression can be found in the result columns of any constituent SELECT, it is an error. ^Each term of the ORDER BY clause is processed separately and may be matched against result columns from different SELECT statements in the compound.

+ +hd_fragment limitoffset {LIMIT} +

### LIMIT and OFFSET clauses

The LIMIT clause is used to place an upper bound on the number of rows -returned by a SELECT statement. ^Any scalar expression may be used in the +returned by the entire SELECT statement. In a compound SELECT, only the +last (right-most) SELECT may contain a LIMIT clause. In a compound SELECT, +the LIMIT clause applies to the entire compound, not just the final SELECT. + +

^Any scalar expression may be used in the LIMIT clause, so long as it evaluates to an integer or a value that can be losslessly converted to an integer. ^If the expression evaluates to a NULL value or any other value that cannot be losslessly converted to an integer, an error is returned. ^If the LIMIT expression evaluates to a negative value, then there is no upper bound on the number of rows returned. ^Otherwise, the