Reputation: 105
I want to get the news that have comments with order of total comments,
I try to this SQL code
SELECT COUNT( comment ) , N . * , C . *
FROM news N, comment C
WHERE N.ID = C.ID_NEWS
but the problem it's return just the first news with total of all comments
is there any solution ?
Upvotes: 0
Views: 37
Reputation: 65363
I think you want a query like this :
SELECT N.ID as comments_order,
count( C.comment ) as total_comments
FROM news N INNER JOIN comment C
ON ( N.ID = C.ID_NEWS )
GROUP BY N.ID
ORDER BY total_comments;
Upvotes: 1