MSSQLCity.Com - All about MS SQL
     
About Us  
SSWUG Articles  
Articles  
FAQ  
Administration  
Backup/Restore  
Connectivity  
Development  
General  
Installation  
OLAP  
Replication  
Transfer/move  
Trouble  
SQL 6.5  
Scripts  
Tips  
Test Exams  
Advertise  
Download  
History  
Search  
Traffic  
Related Links  
     
Your button logo
Add to Favorites
 
     
 


How can I get only the specified number of rows from my query?

Answer:

You can use the SET ROWCOUNT statement or the TOP clause of the select statement (there is no TOP clause in SQL Server 6.5).
There are examples to return only the 10 top rows from the authors table in the pubs database:

SET ROWCOUNT 10
GO
SELECT * FROM pubs.dbo.authors
GO
or

SELECT TOP 10 * FROM pubs.dbo.authors

Read about the SET ROWCOUNT statement in SQL Server Books Online.


 

 
Visit The SQL Server Worldwide User's Group for all the latest news and information about SQL Server, Oracle, DB2 and XML for developers and administrators.

(c) 1997, 2010 Bits on the Wire, Inc