devxlogo

Limiting rows returned by SELECT

Limiting rows returned by SELECT

Question:
In PL/SQL, the following syntax is allowed:

   SELECT * FROM table WHERE ROWNUM 

This would return the first 24 rows of a table.

Is there anything equivalent to this in T-SQL on Microsoft SQL Server 6.5?

Answer:
No. You can limit the number of rows returned with the set ROWCOUNT = N command. But the command does not work the same way as in Oracle. In Oracle, the where rownum builds the result set, calculates which are the first 25 rows that would be returned, and returns only those rows. SQL Server doesn't guarantee what 25 rows are returned when the set ROWCOUNT is used.

devx-admin

Share the Post: