Query help

I have table_one
id(int), name(varchar)

example recordset from table_one
1000 Testone
1001 Testtwo
1002 Testthree

joined on table_two
id(int), sdate(date), edate(date)

example recordset from table_two
1000 01/12/2019     02/15/2019
1000 02/16/2019     03/15/2019
1000 03/16/2019     04/19/2019
1002 01/16/2019     02/13/2019
1002 02/14/2019     04/17/2019

This is a one to many relationship with table_one being primary
I want to select only one row from table_two that has the latest edate value

So result set of desired query would be

1000 Testone 03/16/2019     04/19/2019
1002 Testthree   02/14/2019     04/17/2019

Thanks
LVL 25
dgrafxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott PletcherSenior DBACommented:
SELECT t1.*, oa1.sdate, oa1.edate
FROM dbo.table_one t1
OUTER APPLY (
          SELECT TOP (1) *
          FROM dbo.table_two t2
          WHERE t2.id = t1.id
          ORDER BY edate DESC
) AS oa1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dgrafxAuthor Commented:
Hold on a minute - I'm having some issues ...
Will post back in a bit
dgrafxAuthor Commented:
OK works great Scott!
Thanks!
dgrafxAuthor Commented:
!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.