Wow this question is really hard to formulate succinctly. So, here's the data:
Person:
+----+---------+
| ID | Name |
+----+---------+
| 1 | Bob |
| 2 | Alice |
| 3 | Greg |
| 4 | Lisa |
+----+---------+
Activity:
+----+----------+------------+----------+
| ID | PersonID | Date | Activity |
+----+----------+------------+----------+
| 1 | 1 | 2017-03-01 | foo |
| 2 | 1 | 2017-03-02 | bar |
| 3 | 2 | 2016-12-01 | foo |
| 4 | 3 | 2017-01-15 | foo |
+----+----------+------------+----------+
I want to return all Person
rows whose most-recent Activity
is foo
.
Return:
+----+---------+
| ID | Name |
+----+---------+
| 2 | Alice |
| 3 | Greg |
+----+---------+
Thanks!