dannyluked Posted July 29, 2009 Share Posted July 29, 2009 I have these tables: Blogcomments -blogtitle -comment Blog -title -date -other columns... I want a code that shows the ‘title’ column in the table ‘blog’ but also tells you how many rows contain the same title (column ‘blogtitle’) in the table ‘blogcomments’. For example if my tables looked like this Blogtitle A B C C Blog A B C D The output would be: A - 1 match(‘s) B - 1 match(‘s) C - 2 match(‘s) D - 0 match(‘s) MySQL version 5.1 Quote Link to comment https://forums.phpfreaks.com/topic/167997-cannot-make-correct-query/ Share on other sites More sharing options...
gassaz Posted July 29, 2009 Share Posted July 29, 2009 A query like this??? http://www.phpfreaks.com/forums/index.php/topic,262555.0.html Quote Link to comment https://forums.phpfreaks.com/topic/167997-cannot-make-correct-query/#findComment-886112 Share on other sites More sharing options...
dannyluked Posted July 29, 2009 Author Share Posted July 29, 2009 I just changed the table names and got this: SELECT blogcomments.blogtitle, blogcomments.comment, COUNT(blog.title) FROM blog INNER JOIN blogcomments ON (blog.title=blogcomments.blogtitle) GROUP BY blogcomments.blogtitle but that just give printed "Resource id #10"! Quote Link to comment https://forums.phpfreaks.com/topic/167997-cannot-make-correct-query/#findComment-886122 Share on other sites More sharing options...
gassaz Posted July 29, 2009 Share Posted July 29, 2009 For example if my tables looked like this Blogtitle A B C C Blog A B C D The output would be: A - 1 match(‘s) B - 1 match(‘s) C - 2 match(‘s) D - 0 match(‘s) If you want the results on this way, the sql that you made is wrong. You got the idea.. Try this: SELECT blog.title, COUNT(blogcomments.blogtitle) FROM blog INNER JOIN blogcomments ON (blog.title=blogcomments.blogtitle) GROUP BY blogcomments.blogtitle Quote Link to comment https://forums.phpfreaks.com/topic/167997-cannot-make-correct-query/#findComment-886188 Share on other sites More sharing options...
dannyluked Posted July 29, 2009 Author Share Posted July 29, 2009 Could you please give me the full php code including the connect because when I do it, it shows the title that are in both tables where I want it to count them. So could you please give me the full code that will do this: Blogtitle A B C C Blog A B C D The output would be: A - 1 match(‘s) B - 1 match(‘s) C - 2 match(‘s) D - 0 match(‘s) Thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/167997-cannot-make-correct-query/#findComment-886209 Share on other sites More sharing options...
gassaz Posted July 29, 2009 Share Posted July 29, 2009 I apologize, but my knowledge of php is not good yet,But there are experts here who can help you. Quote Link to comment https://forums.phpfreaks.com/topic/167997-cannot-make-correct-query/#findComment-886215 Share on other sites More sharing options...
dannyluked Posted July 29, 2009 Author Share Posted July 29, 2009 My knowledge of PHP is worse than yours, you have helped me a lot, thanks for your time! Quote Link to comment https://forums.phpfreaks.com/topic/167997-cannot-make-correct-query/#findComment-886217 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.