My query:
SELECT issues.*,
comments.author AS commentauthor,
comments.when_posted AS commentposted
FROM issues
LEFT JOIN (SELECT *
FROM comments
ORDER BY when_posted DESC
LIMIT 1) AS comments ON issues.id=comments.issue
ORDER BY IFNULL(commentposted, issues.when_opened) DESC
My problem with it is the "LIMIT 1" on the third line. That limits all comments to only the newest one, so only issues with the newest comment will be reported back as having a comment at all.
If I removed the "LIMIT 1" part from there, I'd get a row for every comment in an issue, and that's not what I want. What I want is only the newest comment for each issue.
In any case, I'm not sure if my IFNULL part even works because that's not where I'm up to in debugging yet.
So how would I achieve what I wanted?