23.10.2012 Views

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Syntax<br />

SELECT<br />

In the above query, state is ambiguous because it can refer to either database column<br />

pub.customer.state or the result of the substring scalar function in the SELECT list. The ANSI<br />

standard requires that state refers unambiguously to the database column, therefore, the query<br />

groups the result by the database column. The same principle holds true for ambiguous<br />

references that appear in WHERE, ON, and HAVING clauses.<br />

TOP clause<br />

TOP n<br />

Limits the rows returned by an OpenEdge <strong>SQL</strong> query at the statement level.<br />

When the TOP clause is specified, the OpenEdge <strong>SQL</strong> server returns the maximum number<br />

of rows specified in the clause. The maximum number allowed for the TOP clause is<br />

2,147,483,647.<br />

Example In the following example, the SELECT statement returns the names of the five customers with the<br />

highest account balance:<br />

SELECT TOP 5 FROM pub.customer<br />

ORDER BY balance DESC;<br />

The TOP clause is only allowed in a top-level SELECT statement. Therefore, the TOP clause cannot<br />

be used in the following instances:<br />

• As part of a subquery<br />

• When derived tables are used in the query<br />

• Within the CREATE TABLE, CREATE VIEW, UPDATE, and INSERT statements<br />

• In queries used with set operators such as UNION, INTERSECT, and MINUS<br />

In instances when the server performs aggregation on the result set (i.e., through an aggregate<br />

function such as SUM or MAX, a GROUP BY clause, or the DISTINCT keyword) the TOP clause should<br />

be interpreted as being applied last. When there is no aggregation in the SELECT statement and<br />

the result set is also sorted, then <strong>SQL</strong> will optimize sorting in order to increase query<br />

performance.<br />

SELECT TOP is the functional equivalent of the Oracle ROWNUM functionality. Note that SELECT<br />

TOP is defined simply in terms of a limit on the result set size, and the optimizer determines how<br />

to use this limit for best data access. Thus, SELECT TOP does not have all the "procedural rules"<br />

used to define the meaning of the Oracle ROWNUM phrase.<br />

49

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!