Pages

Monday, February 18, 2008

TOP in SQL Server

TOP keyword is a one of those keywords that has been added by Microsoft to the ANSI SQL. Often developers who are used to T-SQL and are in the process of adapting themselves to PL-SQL find this key word suddenly missing. The TOP keyword is often used to reduce the size of the result set returned by a SQL query. Hence the TOP keyword is the keyword that is applied the last in the sequence of operations performed by the SQL engine. Also the TOP keyword is used to get a certain fixed number or percentage of rows from a table or view.

The TOP keyword is usually followed by an expression which would tell the SQL engine the number of rows of the result set that have to be returned.

SELECT TOP (5) * FROM Northwind.dbo.EMPLOYEE

2 comments:

Anonymous said...

select emp_code,count(*)
from Emp_Matser
group by emp_code
having count(*)>1


I think it work fine...

Anonymous said...

First of all thanks for visiting my blog. Your query is to return duplicate records not for getting top records with in the table. or limit the no. of records returned from the query.....