I have these two tables:
Person:
+----+-------+
| ID | name |
+----+-------+
| 1 | John |
| 2 | Frank |
+----+-------+
Position:
+----+---------+----------+------------+
| ID | name | personID | startDate |
+----+---------+----------+------------+
| 1 | Cashier | 1 | 2013-01-01 |
| 2 | Manager | 1 | 2013-04-23 |
| 3 | Cashier | 2 | 2014-02-01 |
+----+---------+----------+------------+
The Position
table tracks various positions that a person has held.
How can I create a listing that shows each person and their current position (which would be whatever position has the latest start date)? Essentially I need to limit the JOIN
of the Position
table to only return one result.
I tried the following code.
SELECT p.id, h.positionID FROM person p JOIN position h ON p.id = h.personID