Hey guys, I have the following query below, where I list all posts, number of comments and the user who created it, but also wanted to list the last user who commented on each post, can you do all this in just a query?
SELECT post.titulo, COUNT(comentario.codigo), autor.nome, MAX(comentario.codigo_usuario) FROM post JOIN comentario JOIN usuario autor JOIN usuario ON post.codigo_usuario = autor.codigo AND post.codigo = comentario.codigo_topico AND usuario.codigo = comentario.codigo_usuario GROUP BY post.codigo