I have multiple rows with a parent ID that associates related rows. I want to select the email address where Status = 'active', for the parent ID, and if there's multiple rows with that condition, I want to pick the most recently modified (createDate).
Basically I have two+ records, parent ID 111. The first record has [email protected] with a status of 'active', and the second record has [email protected] with a status of 'unsubscribed'. How do I select just ID 111 with [email protected]?
How would I go about this?
Table Data:
ID ParentID Email Status CreateDate
1000919 1000919 [email protected] bounced 2/5/18
1017005 1000919 [email protected] active 1/6/18
1002868 1002868 [email protected] active 12/31/17
1002868 1002868 [email protected] active 12/31/17
1002982 1002982 [email protected] held 2/7/18
1002982 1002982 [email protected] held 2/7/18
1002990 1002990 [email protected] active 10/26/18
1003255 1003255 [email protected] active 2/7/18
Expected Result:
ParentID Email Status CreateDate
1000919 [email protected] active 1/6/18
1002868 [email protected] active 12/31/17