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 < 25

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 < 25 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.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist