Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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 TWHERE RowNum <=6