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.
I think that if you use
L.Id = 24, you are going to get only ONE row back. IMO you should be filtering by theL.UserorL.UserId, not theL.IdFor a list of all projects, this is what you can do.
For a single project that you know the project detail for, just use an
ORDER BY