I have the following two tables:
t1
+----+------+-----+
| id | name | age |
+----+------+-----+
| 1 | bob | 42 |
| 2 | dave | 12 |
| 3 | mary | 78 |
| 4 | kim | 41 |
+----+------+-----+
t2
+----+-------+------------------+
| id | t1_id | date |
+----+-------+------------------+
| 1 | 1 | 12/26/2014 14:32 |
| 2 | 1 | 12/26/2014 16:32 |
| 3 | 1 | 12/27/2014 14:32 |
| 4 | 2 | 12/26/2014 15:32 |
| 5 | 4 | 12/26/2014 14:32 |
| 6 | 4 | 12/27/2014 14:32 |
+----+-------+------------------+
I wish to obtain the following results (only include the most current JOINed date from t2):
+----+------+-----+------------------+
| id | name | age | date |
+----+------+-----+------------------+
| 1 | bob | 42 | 12/27/2014 14:32 |
| 2 | dave | 12 | 12/26/2014 15:32 |
| 3 | mary | 78 | null |
| 4 | kim | 41 | 12/27/2014 14:32 |
+----+------+-----+------------------+
The following gets me close, but JOINs all the matches from t2. How do I just include the most recent?
SELECT t1.id, t1,name, t1.age, t2.date
FROM t1
LEFT OUTER JOIN t2 ON t2.t1_id=t1.id;