I can't believe I'm getting so stuck on what seems like such a simple query.
I need to get back the User of a Log for a given Project which has the maximum DateLogged value. I've rewritten it a million ways but this is the way which expresses what I want the clearest -
SELECT L.User
FROM Log AS L
WHERE L.Id = 24
GROUP BY L.ProjectId
HAVING MAX(L.DateLogged) = L.DateLogged
But that throws a "Column 'Log.DateLogged' is invalid in the HAVING clause because it is not contained in either an aggregate function or the GROUP BY clause." But I don't want it grouped by DateLogged, nor do I want it in an aggregate function.