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 2000 Forums
 SQL Server Development (2000)
 How to retreive 6 most recent records

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-03-18 : 08:00:12
Kaleem writes "Hi,
I want to retreive 6 most recent records of EACH ITEM. Table(Receiving) structure is

RecId, Date_Time, ItemCode, Quantity

I tried
Select top 6 * from Receiving group by RecId, Date_Time, ItemCode, Quantity order by Date_Time Desc

but it doesnt work.

PK is RecId and ItemCode
Sql Server version is 2000
Windows version is 2000 Server"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-03-18 : 08:06:29

Group by will minimize the records. Can you post the result?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-03-18 : 08:24:23
Select RecId, Date_Time, ItemCode, Quantity
From myTable as t1
Where (Select count(distinct Date_Time) from myTable Where RecId = t1.RecId and Date_Time >= t1.Date_Time)<=6
Order By RecId, Date_Time desc

Go with the flow & have fun! Else fight the flow
Go to Top of Page
   

- Advertisement -