O'Reilly logo

Inside Microsoft® SQL Server™ 2005: T-SQL Querying by Dejan Sarka, Lubor Kollar, Itzik Ben-Gan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

SELECT TOP

In a SELECT query or table expression, TOP is used with an ORDER BY clause to limit the result to rows that come first in the ORDER BY ordering. You can specify the quantity of rows you want in one of two ways: as an exact number of rows, from TOP(0) to TOP(9223372036854775807) (the largest BIGINT value), or as a percentage of rows, from TOP(0E0) PERCENT to TOP(100E0) PERCENT, using a FLOAT value. In Microsoft SQL Server 2000, you could only use a constant to specify the limit. SQL Server 2005 supports any self-contained expression, not just constants, with TOP.

To make it clear which rows are the "top" rows affected by a TOP query, you must indicate an ordering of the rows. Just as you can’t tell top from bottom unless you know which ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required