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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Using Top in select

Author  Topic 

oasis1
Starting Member

35 Posts

Posted - 2012-10-02 : 17:01:54
is there a way to use Top to find the top 10 for example for each year rather than just returning the top 10 over all? mahalo, Brew

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-02 : 17:22:24
yep...but not using top. you can use below logic


SELECT
FROM
(
SELECT ROW_NUMBER() ORDER (PARTITION BY yearfield ORDER BY yoursortfield) AS seq,*
FROM table
)t
WHERE seq<=10


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -