Select most recent record in sub child
Posted
by
Omar
on Stack Overflow
See other posts from Stack Overflow
or by Omar
Published on 2011-03-06T08:04:09Z
Indexed on
2011/03/06
8:10 UTC
Read the original article
Hit count: 282
I have the following tables/columns:
Parent:
ParentID
Child:
ChildID
ParentID
SubChild:
SubChildID
ChildID
Date
Parent has 1 to Many relationship with Child
Child has 1 to Many relationship with SubChild
For every Parent, I need to get the SubChild with the most recent Date value.
How can I do this using SQL. I've tried using MAX(Date),
but I can't seem to figure out how to join Parent and Child successfully.
The ideal result set would contain all the Parents joined with all the SubChild columns of the latest record.
Note: using MS SQL 2005+
© Stack Overflow or respective owner