This is a mirror of official site: http://jasper-net.blogspot.com/

Select TOP With TIES in SQL Server

| Wednesday, January 5, 2011
The SQL Server TOP Expression returns only the first set of rows that is either a number or a percent of rows. If you want additional rows to be returned from the base result set if duplicate values exists in the qualified set of results, then use TOP..WITH TIES as shown in the example below:

USE Northwind
GO
-- TOP vs TOP WITH TIES
-- By SqlServerCurry.com

-- Using TOP Expression
SELECT TOP 3
OrderID, UnitPrice, Quantity
FROM [Order Details]
ORDER BY Quantity DESC

-- Using TOP WITH TIES
SELECT TOP 3 WITH TIES
OrderID, UnitPrice, Quantity
FROM [Order Details]
ORDER BY Quantity DESC

Read more: SQL Server curry

Posted via email from .NET Info

0 comments: