The FIRST, TOP, and LIMIT clauses allow you to return, update, or delete a subset of the rows that satisfy the WHERE clause. The FIRST, TOP, and LIMIT clauses can be used within any SELECT query block that includes an ORDER BY clause. The FIRST and TOP clauses can also be used in DELETE and UPDATE query blocks.
The FIRST, TOP, and LIMIT clauses are row limitation clauses and they have the following syntax:
rowlimitationoption1 : FIRST  TOP { ALL  limitexpression } [ START AT startatexpression ]
rowlimitationoption2 : LIMIT { [ offsetexpression, ] limitexpression  limitexpression OFFSET offsetexpression }
limitexpression : simpleexpression
startatexpression : simpleexpression
offsetexpression : simpleexpression
simpleexpression : integer  variable  ( simpleexpression )  ( simpleexpression { +    * } simpleexpression )
Only one row limitation clause can be specified for a SELECT clause. When specifying these clauses, an ORDER BY clause is required to order the rows in a meaningful manner.
rowlimitationoption1 This type of clause can be used with SELECT, UPDATE, or DELETE query blocks. The TOP and START AT arguments can be simple arithmetic expressions over host variables, integer constants, or integer variables. The TOP argument must evaluate to a value greater than or equal to 0. The START AT argument must evaluate to a value greater than 0. If startatexpression is not specified the default is 1.
The expression limitexpression + startatexpression 1'
must evaluate to a value less than 9223372036854775807 = 2^641. If the argument of TOP is ALL, all rows starting at startatexpression are returned.
The TOP limitexpression START AT startatexpression
clause is equivalent to LIMIT (startatexpression1), limitexpression
or LIMIT limitexpression OFFSET (startatexpression1)
.
rowlimitationoption2
This type of clause can be used only in SELECT query blocks. The LIMIT and OFFSET arguments can be simple arithmetic
expressions over host variables, integer constants, or integer variables. The LIMIT argument must evaluate to a value greater
than or equal to 0. The OFFSET argument must evaluate to a value greater than or equal to 0. If offsetexpression is not specified, the default is 0. The expression limitexpression + offsetexpression
must evaluate to a value less than 9223372036854775807 = 2^641.
The row limitation clause LIMIT offsetexpression, limitexpression
is equivalent to LIMIT limitexpression OFFSET offsetexpression
. Both of these constructs are equivalent to TOP limitexpression START AT (offsetexpression + 1)
.
The LIMIT keyword is disabled by default. Use the reserved_keywords option to enable the LIMIT keyword.
Discuss this page in DocCommentXchange.

Copyright © 2012, iAnywhere Solutions, Inc.  SQL Anywhere 12.0.1 