rcouser Posted January 28, 2010 Share Posted January 28, 2010 Hey there, I have a query regards most commented news on my site. The database structure is Table One: comments comment_id comment_email comment_name comment_description comment_date news_id Table Two: news news_id news_title How do I use sql to find the find news_title of the top 5 news stories with the most comments? Any help would be much appreciated. Regards Quote Link to comment https://forums.phpfreaks.com/topic/190108-most-commented-news/ Share on other sites More sharing options...
kickstart Posted January 28, 2010 Share Posted January 28, 2010 Hi Something like this. SELECT a.news_title, COUNT(b.comment_id) AS commentCount FROM news a LEFT OUTER JOIN comments b ON a.news_id = b.news_id ORDER BY commentCount DESC LIMIT 5 All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/190108-most-commented-news/#findComment-1003024 Share on other sites More sharing options...
rcouser Posted January 28, 2010 Author Share Posted January 28, 2010 Hi kickstart, Thank you very much for the quick responce. Works great. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/190108-most-commented-news/#findComment-1003040 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.