using LIMIT within a SELECT statment
-
I am trying to limit the number of items returned from a SQL Server (SQL Server 2000). However when I do something like this ASP.NET gets mad at me:
SELECT * FROM SomeWhere WHERE Something = 'SomeCondition' LIMIT 5
Basically I only want the first 5 results returned. This worked in my experience in MySQL. Could anyone show me how to do it in SQL Server 2000? Matt Newman
-
I am trying to limit the number of items returned from a SQL Server (SQL Server 2000). However when I do something like this ASP.NET gets mad at me:
SELECT * FROM SomeWhere WHERE Something = 'SomeCondition' LIMIT 5
Basically I only want the first 5 results returned. This worked in my experience in MySQL. Could anyone show me how to do it in SQL Server 2000? Matt Newman
SELECT TOP 5 * FROM SomeWhere WHERE Something = 'SomeCondition'
MSSQL doesn't support "LIMIT x, y" but it can be emulated through a somewhat... icky... nested subselection. -- Henrik Stuart (http://www.unprompted.com/hstuart/)
-
SELECT TOP 5 * FROM SomeWhere WHERE Something = 'SomeCondition'
MSSQL doesn't support "LIMIT x, y" but it can be emulated through a somewhat... icky... nested subselection. -- Henrik Stuart (http://www.unprompted.com/hstuart/)
-
Also consider set rowcount n to stop processing of the result set after n rows (and set rowcount 0 to reset). The set rowcount is especially useful in a stored proc where you want to pass n (the # of rows) as a variable from your components/application. Cheers, Lee. Lee H Fuller lee@fullerdata.com