Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6022541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:52:21+00:00 2026-05-23T03:52:21+00:00

This is for a custom forum I am working on. i need to select

  • 0

This is for a custom forum I am working on. i need to select all threads, get the number of posts in each thread and also the last post in each thread. I can get the number of posts, but my query is returning the first post rather than the last.

SELECT thread_id, thread_title, p.*, COUNT(p.post_id) AS Posts
   FROM forums_threads
   JOIN forums_posts AS p ON post_thread_id=thread_id
   WHERE thread_forum_id=84
   GROUP BY thread_id
   ORDER BY thread_date DESC, post_date DESC
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:52:21+00:00Added an answer on May 23, 2026 at 3:52 am

    As @mixman suggests, you need to link to forum_posts twice: once to get the aggregate amounts (post count and maximum post date), and once to get the actual content of that last post (and I’m assuming that by “last” you mean “most recent”) in the thread:

    SELECT ft.thread_id, ft.thread_title, fp.*, pmin.postcount
    FROM forums_threads AS ft
    JOIN (
          SELECT post_thread_id, MAX(post_date), COUNT(post_id) AS postcount
          FROM forums_posts
          GROUP BY post_thread_id
         ) AS pmin ON ft.thread_id=pmin.post_thread_id
    JOIN forums_posts AS fp ON fp.post_thread_id=pmin.post_thread_id AND fp.post_date = pmin.post_date
    WHERE ft.thread_forum_id=84
    ORDER BY ft.thread_date DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this custom textbox that I am working on and I can use
How to find all paths between two vertices using QuickGraph? This is my custom
I'd like to create a custom input form that collects employees hours. This data
A web service return to my flex3 client this custom exception: <SOAP-ENV:Fault xmlns:ro=urn:Gov2gLibrary xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/
Is there a standard method I can use in place of this custom method?
I am leaking memory on this: my custom class: + (id)vectorWithX:(float)dimx Y:(float)dimy{ return [[[Vector
Is it possible to have nested set capabilities in this somewhat custom setup? Consider
This is my custom model binder. I have my breakpoint set at BindModel but
Check this code (My Custom Keyboard): -(IBAction) updateTextBackSpace:(id)sender { if([txtview.text length]>0) { NSString *deletedLastCharString
This code lets me display/hide a custom message msg_one msg_two msg_three when the appropriate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.