Q&A for Drupal developers and administrators
SELECT p.id ,c.text FROM posts p LEFT JOIN( SELECT c.postid ,MAX(c.creationdate) as latest_comment FROM comments c GROUP BY c.postid) s ON s.postid = p.id JOIN comments c ON p.id = c.postid where s.latest_comment = c.creationdate