Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Retrieving first n rows from a large query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2007-02-15 : 09:26:04
Sriram writes "Hi,

I want to retrieve only the first n rows from a query which returns a large number of rows.

Say,

select empno, name from emp where deptno=100

returns 1000 rows.

I want to improve the query so that it returns only the first 10 rows and not 1000 rows.

Thanks in Advance,
Sriram."

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-02-15 : 09:53:59
SELECT TOP 10 EmpNo, Name
FROM Emp
WHERE DeptNo = 100
ORDER BY ... -- Name? EmpNo? Shoe size?



Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -