May 27, 2004 at 3:29 pm
Hi, All
Here is my dilema..
I want to pull each ID for lastest trans_date.
Data:
May 27, 2004 at 3:48 pm
Try
SELECT
N.[ID], N.TRANS_DATE, N.AMOUNT
FROM
tblName N
INNER JOIN
(SELECT [ID], MAX(TRANS_DATE) TT FROM tblName T2 GROUP BY [ID]) TQ
ON
N.[ID] = TQ.[ID] AND
N.TRANS_DATE = TQ.TRANS_DATE
May 27, 2004 at 3:58 pm
Thx..
Jay
May 28, 2004 at 2:44 am
Hi Jay,
I often heard inner join is to be preferred always. But there is another way to solve your problem using a simple where clause. This is easyer to write down and estimatet execution plan shows no difference in performance. I would like to know if you get the same result using this query:
select * from tablename a where a.trans_date =
(select max (trans_date) from tablename where id = a.id)
Karsten
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply