Se necesita ayuda de MySql Query

I have a table with comments. These comments are related to another table of questions, through 1-to-many relation, i.e. 1 question to many comments. Now, I want a list of 5 questions with the maximum number of comment counts (in succession of course). So, my query should return something like:

Question Id:4 with 30 comments
Question Id:2 with 27 comments
Question Id:11 with 22 comments
Question Id:5 with 15 comments
Question Id:14 with 10 comments

Can I achieve this through 1 query or multiple ones? And how?

preguntado el 28 de agosto de 11 a las 03:08

1 Respuestas

This query gets the data you need. You can handle the output formatting as desired.

select questionid, count(commentid) as commentcount
from question q
inner join comment c on q.questionid = c.questionid
group by questionid
order by commentcount desc
limit 5;

Respondido 28 ago 11, 07:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.