August 1, 2005 at 10:00 am
Can any one help me for the query marked in red?
........... LEFT OUTER JOIN (SELECT ItemId,UserId,Max(EffTime) as ETime FROM ItemAuditTrail WHERE NewValue ='Matched' GROUP BY ItemId,UserId ) AS T3 ON T3.ItemId = Item.Id
15058509 | 423 | Name0 | 01:40.9 |
15058509 | 425 | Name1 | 01:47.9 |
15058509 | 447 | Name2 | 59:38.4 |
query gives me the output as mentioned above, means it does not give me single record if there are more then one users. I want only one row with last effective time.
15058509 | 425 | Name1 | 01:47.9 |
Thanks.
August 1, 2005 at 10:26 am
You could possibly insert the record set into a temp table, and query out of the temp table:
SELECT MAX(EffTime) from #tempTable
There is probably a more elegant solution to this, but this may work.
August 1, 2005 at 3:47 pm
Ok i tried your idea but this still gives all rows as i want to return userid too
August 2, 2005 at 12:19 am
How about
SELECT TOP 1 ItemId,UserId,Max(EffTime) as ETime FROM ItemAuditTrail WHERE NewValue ='Matched' GROUP BY ItemId,UserId ORDER BY EffTime DESC
This will give you the first record with the largest time value.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply