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 2012 Forums
 Transact-SQL (2012)
 Help to build Query

Author  Topic 

Pete_N
Posting Yak Master

181 Posts

Posted - 2014-11-09 : 10:21:28
IF I have two tables, tTrans and tAccounts,
tTrans has a guid field (laccount) which holds the Guid for tAccounts
and a datefield (createdDate) when the records was created

tTran holds multiple records for each record in tAccount. What I am trying to do is create a query on tAccount to return the latest record in tTrans for each record in tAccount.

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-10 : 09:18:01
[code]
select t.*
from tAccounts a
join tTrans t
on a.laccount = t.laccount
group by t.laccount, t.createdate, t. ... -- the other columns in t
having t.createdDate = max(t.createdDate)

[/code]
Go to Top of Page
   

- Advertisement -