EKINdesigns Posted January 25, 2008 Share Posted January 25, 2008 I am trying to select from 3 different tables: categories, topics, and users. I need to select all the categories whether or not there are topics in them. If there are topics i need to get the total amount of topics as well as the most recent one defined my `date`. I also need to get the users information who posted each topic. This is what I have so far. Currently if there are no topics in the category it will only return one category when there are actually multiple. I also can't figure out how to select the most recent topic information. SELECT `forums`.{$select} , COUNT(`topics`.`id`) AS `topic_count` , MAX(`topics`.`date`) AS `recent_topic_date` FROM `forums` LEFT JOIN `topics` ON `topics`.`fid` = `forums`.`id` LEFT JOIN `users` ON `users`.`id` = `topics`.`poster` WHERE `forums`.`cid`='{$id}' GROUP BY `topics`.`fid` Quote Link to comment https://forums.phpfreaks.com/topic/87826-complex-mysql-help/ Share on other sites More sharing options...
fenway Posted January 26, 2008 Share Posted January 26, 2008 Be careful, COUNT doesn't count nulls. Quote Link to comment https://forums.phpfreaks.com/topic/87826-complex-mysql-help/#findComment-450120 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.