TOP clause
- Last Updated: March 30, 2020
- 2 minute read
- OpenEdge
- Version 12.2
- Documentation
Limits the rows returned by an OpenEdge SQL query at the statement level and is supported in subqueries.
Syntax
|
Parameters
- n
-
Indicates the number of records per table.
- [ column_name [, column_name ] .....| * ]
-
Indicates the columns within a table.
When the
TOPclause is specified, the OpenEdge SQL server returns the maximum number of rows specified in the clause. The maximum number allowed for the TOP clause is 2,147,483,647.
Example
In
the following example, the SELECT statement returns
the names of the five customers with the highest account balance:
|
The TOP clause is only allowed
in a top-level SELECT statement. Therefore, the TOP clause
cannot be used in the following instances:
- When derived tables are used in the query
- Within the
CREATE TABLE,CREATE VIEW,UPDATE, andINSERTstatements - In queries used with set operators such as
UNION,INTERSECT, andMINUS
In instances when the server
performs aggregation on the result set (i.e., through an aggregate
function such as SUM or MAX, a GROUP
BY clause, or the DISTINCT keyword) the TOP clause should
be interpreted as being applied last. When there is no aggregation
in the SELECT statement and the result set is also
sorted, then SQL will optimize sorting in order to increase query
performance.
SELECT TOP is the functional
equivalent of the Oracle ROWNUM functionality.
Note that SELECT TOP is defined
simply in terms of a limit on the result set size, and the optimizer
determines how to use this limit for best data access. Thus, SELECT
TOP does not have all the "procedural rules" used to define
the meaning of the Oracle ROWNUM phrase.