List the owner of the post and the last user who commented. Mysql

0

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
    
asked by anonymous 05.02.2017 / 15:07

1 answer

-2

You can do this, you need to have an attribute of the DATE or DATETIME genre, which stores the date the post was made, it all depends on how you have built the database.

    
05.02.2017 / 17:10