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 2012 Forums
 Transact-SQL (2012)
 show top 6 records from every category

Author  Topic 

kirank
Yak Posting Veteran

58 Posts

Posted - 2014-02-05 : 11:32:02
Hi,

i wanted to retrieve latest 6 records from transaction table, where transaction table contain multiple no of records.

here i wanted to populate all latest 6 records by every category id.

plz help me to work on this query



---------------------------

http://codingstuffsbykiran.blogspot.com | http://webdevlopementhelp.blogspot.com

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-02-05 : 12:58:40
One way is to use the ROW_NUMBER function:
SELECT
*
FROM
(
SELECT
*
,ROW_NUMBER() OVER (PARTITION BY category_id ORDER BY date_column DESC) AS RowNum
FROM
YourTableName
) AS T
WHERE
RowNum <=6
Go to Top of Page

kirank
Yak Posting Veteran

58 Posts

Posted - 2014-02-06 : 11:45:29
Thanks it works :)

---------------------------

http://codingstuffsbykiran.blogspot.com | http://webdevlopementhelp.blogspot.com
Go to Top of Page
   

- Advertisement -