I am trying to follow the instructions in this answer how to get the latest row in the joined table.
I have two tables.
Projects : id, title
Status : project_id, status_id, created(DATETIME)
When I know the project ID (example = 2) I have the correct query to select the latest status update.
SELECT projects. * , project_state_project_map.status_id AS status,
project_state_project_map.created AS status_created
FROM projects
LEFT JOIN (
SELECT *
FROM project_state_project_map
WHERE project_id = 2
ORDER BY created DESC
LIMIT 1
)
project_state_project_map ON project_state_project_map.project_id = projects.id
WHERE projects.id = 2
LIMIT 1
However, I cannot figure out how to select all projects with their current status. What do I have to change to the sql to get all projects with their latest states.