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.
| 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, QuantityI tried Select top 6 * from Receiving group by RecId, Date_Time, ItemCode, Quantity order by Date_Time Descbut it doesnt work.PK is RecId and ItemCodeSql Server version is 2000Windows 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?MadhivananFailing to plan is Planning to fail |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-03-18 : 08:24:23
|
Select RecId, Date_Time, ItemCode, Quantity From myTable as t1Where (Select count(distinct Date_Time) from myTable Where RecId = t1.RecId and Date_Time >= t1.Date_Time)<=6Order By RecId, Date_Time descGo with the flow & have fun! Else fight the flow |
 |
|
|
|
|
|