Jump to content

Complex MySQL HELP!


EKINdesigns

Recommended Posts

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`

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.