onedumbcoder Posted December 5, 2008 Share Posted December 5, 2008 I am having problems if a join query. I am creating a forum. I am trying to grab subjects from the table, but my work only retrieves only those subjects that have posted items in them. can someone help me correct this so that it also grabs forums with no posts or replies? $query = "SELECT forum.name as a, COUNT(forum_post.id) as b, COUNT(forum_reply.id) as c FROM (forum LEFT JOIN forum_post ON forum_post.forum_id=forum.id) LEFT JOIN forum_reply ON forum_reply.post_id=forum_post.id WHERE forum.owner_id='1' AND forum.forum_type='2' ORDER BY forum.name"; Quote Link to comment https://forums.phpfreaks.com/topic/135593-query-not-returning-the-right-number/ Share on other sites More sharing options...
fenway Posted December 5, 2008 Share Posted December 5, 2008 It's a LEFT JOIN...there should be no issue. Quote Link to comment https://forums.phpfreaks.com/topic/135593-query-not-returning-the-right-number/#findComment-706479 Share on other sites More sharing options...
onedumbcoder Posted December 5, 2008 Author Share Posted December 5, 2008 but there is instead of printing out lets say "General talk" and "tech talk" it is only printing out "tech talk", even worse the number of post it displays are the post in General talk plus the post tech talk Quote Link to comment https://forums.phpfreaks.com/topic/135593-query-not-returning-the-right-number/#findComment-706508 Share on other sites More sharing options...
fenway Posted December 5, 2008 Share Posted December 5, 2008 Where's the group by? Quote Link to comment https://forums.phpfreaks.com/topic/135593-query-not-returning-the-right-number/#findComment-706705 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.