DECLARE @temp TABLE (
RowId INT IDENTITY
, SalesId INT
)
INSERT INTO @temp (
SalesId
)
SELECT Salesid
FROM temp
ORDER BY dealid DESC
SELECT TOP 5 t.SalesId
FROM @temp t
INNER JOIN (
SELECT SalesId, MIN(RowId) AS RowId
FROM @temp
GROUP BY SalesId
) x ON t.RowId = x.RowId
ORDER BY x.RowId
Depending on relationship between SalesId and DealId, you could also group by Sales and then order by the sum(DealId) desc and take top 5 that way.
_____________________________________________________________________
- Nate
@nate_hughes