SELECT a.*, s.app_status
FROM application AS a
JOIN (
SELECT application_id, app_status, created_at
FROM application_status
WHERE created_at = (
SELECT MAX(created_at)
FROM application_status AS sub
WHERE sub.application_id = application_status.application_id
) AND app_status IN ('accepted')
) AS s ON a.id = s.application_id
WHERE a.form_id = 'staff'
ORDER BY created_at DESC
LIMIT 10
OFFSET 0;
SELECT a.*, s.app_status
FROM application AS a
JOIN (
SELECT application_id, app_status, created_at
FROM application_status
WHERE created_at = (
SELECT MAX(created_at)
FROM application_status AS sub
WHERE sub.application_id = application_status.application_id
) AND app_status IN ('accepted')
) AS s ON a.id = s.application_id
WHERE a.form_id = 'staff'
ORDER BY created_at DESC
LIMIT 10
OFFSET 0;