dimanche 28 juin 2015

SQL - Return Last Update Date

I'm trying to return the LastUpdateDate based on a ParentID. This date can come from any of it's child tables. Let's say there are two child tables. Child one has a one to one relationship with the Parent and child two has a many to many relationship. See test tables below. Any help would be appreciated.

Parent Table

ParentID    Name      LastUpdateDate
1        Parent John     2014-06-26
2        Parent Mark     2004-07-27
3        Parent Bob      2009-04-07
4        Parent Jo       2014-09-26

ChildOne Table (1-1 Relationship)

ChildOneID  ParentID    Name            LastUpdateDate
10             1    FirstChild Tom        2011-03-12
20             2    FirstChild David      2014-08-11
30             3    FirstChild Sally      2009-04-06
40             4    FirstChild Jane       2014-11-26

ChildTwo Table (many - many Relationship)

ChildTwoID  ParentID    Name            LastUpdateDate
100             1   SecondChild Phil       2014-03-12
200             2   SecondChild Smith      2012-08-10
300             3   SecondChild Paul       1999-04-06
400             4   SecondChild Ed         2010-11-26
500             2   SecondChild Donna      2010-08-10
600             4   SecondChild Melissa    2008-10-16

Aucun commentaire:

Enregistrer un commentaire