2 ms·
The SQL in question which was problematic for me (tables renamed): SELECT posts.*, MAX(COALESCE(comments.created_at, posts.created_at)) AS latest_timestamp FRO
by ThrustVectoring 5y ago
The SQL in question which was problematic for me (tables renamed):
SELECT posts.*, MAX(COALESCE(comments.created_at, posts.created_at)) AS latest_timestamp FROM posts LEFT OUTER JOINS comments ON posts.id = comments.post_id GROUP BY posts.id ORDER BY latest_timestamp desc
In short, this is sorting posts by the most recent comment, with a fallback to the post date if the post has no comments on it. Hard to get rid of the grouping here and get the same data back.
- e12e 5y agoI see, that makes more sense.