[ https://issues.apache.org/jira/browse/TRAFODION-2973?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16380680#comment-16380680 ]
ASF GitHub Bot commented on TRAFODION-2973: ------------------------------------------- Github user DaveBirdsall commented on a diff in the pull request: https://github.com/apache/trafodion/pull/1458#discussion_r171317972 --- Diff: docs/sql_reference/src/asciidoc/_chapters/sql_statements.adoc --- @@ -6989,20 +6989,22 @@ By abstracting the complicated parts of the query into simpler, separate and log + specifies the unique name of the CTE to be created, which is a valid SQL identifier with a maximum of 128 characters. Duplicate names are not allowed in a single with-clause. -* `"[" ANY _N_ "]" | "[" FIRST _N_ "]"` +* `"[" ANY _N_ "]" | "[" FIRST _N_ "]" | "[" LAST _N_ "]" ` + specifies that _N_ rows are to be returned (assuming the table has at least _N_ rows and that the qualification criteria specified in the WHERE clause, if any, would select at least _N_ rows) and you do not care which _N_ rows are chosen (out of the qualified rows) to actually be returned. + -_You must enclose ANY N or FIRST N in square brackets ([])._ The quotation marks ("") around each square bracket in +You must enclose `ANY _N_`, `FIRST _N_` or `LAST _N_` in square brackets ([]). The quotation marks ("") around each square bracket in the syntax diagram indicate that the bracket is a required character that you must type as shown (for example, [ANY 10] or [FIRST 5]). Do not include quotation marks in ANY or FIRST clauses. + [FIRST _N_] is different from [ANY _N_] only if you use ORDER BY on any of the columns in the select list to sort the result table of the SELECT statement. _N_ is an unsigned numeric literal with no scale. If _N_ is greater than the number of rows in the table, all rows are returned. [ANY _N_] and [FIRST _N_] are disallowed in nested SELECT statements and on either side of a UNION operation. ++ +`[LAST _N_]` performs a full table scan and calculates elapsed time. The _N_ must be 0 or 1. `[LAST _0_]` does not return any rows. `[LAST _1_]` returns only the last qualified row. --- End diff -- "... performs a full table scan ..." This is not quite correct. Our query plan might have key predicates that limit us to less than a full table scan, for example. A more accurate description might be "... performs the entire query ...". > Add syntax and examples of *[LAST N] (SELECT Statement)* in *Trafodion SQL > Reference Manual* > --------------------------------------------------------------------------------------------- > > Key: TRAFODION-2973 > URL: https://issues.apache.org/jira/browse/TRAFODION-2973 > Project: Apache Trafodion > Issue Type: Documentation > Reporter: Liu Yu > Assignee: Liu Yu > Priority: Major > -- This message was sent by Atlassian JIRA (v7.6.3#76005)