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 7185511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:25:53+00:00 2026-05-28T18:25:53+00:00

I am trying a code my own forum system, and everything is going quite

  • 0

I am trying a code my own forum system, and everything is going quite well, except for 1 thing.

When browsing a category, how would I be able to retrieve the username of both the creator of each thread, but also the username of the user who posted the last post in each thread?

This is what I have so far, but I still only retrieve 1 username (the OP’s username).

SELECT 
    c_name, <-- category name
    t_title, <-- thread title
    t_by, <-- thread started by user id
    username, <-- username of the thread starter
    p_by, <-- post by user id
    p_date, <-- post posted date
    COUNT(p_id) as total_posts
FROM
    forum_categories
LEFT JOIN
    forum_threads
ON
    t_cat = c_id
LEFT JOIN
    forum_posts
ON
    p_thread = t_id
LEFT JOIN
    users
ON
    t_by = id
AND
    p_by = id
WHERE
    t_cat = 1

As you can see, I only retrieve the username of the thread starter.
Is it even possible to do this with a single query?

Thanks

  • 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-28T18:25:55+00:00Added an answer on May 28, 2026 at 6:25 pm

    You should left join for both users in your query:

    SELECT 
        c_name,           <-- category name
        t_title,          <-- thread title
        t_by,             <-- thread started by user id
        ut_by.username,   <-- username of the thread starter
        p_by,             <-- post by user id
        up_by.username,   <-- username of the post
        p_date,           <-- post posted date
        COUNT(p_id) as total_posts
    FROM
        forum_categories
           LEFT JOIN
        forum_threads
           ON t_cat = c_id
           LEFT JOIN
        forum_posts
           ON p_thread = t_id
           LEFT JOIN
        users ut_by
          ON t_by = ut_by.id 
          LEFT JOIN
        users up_by
          on p_by = up_by.id
    WHERE
        t_cat = 1
    

    This is an answer about get user details for both. Disclaimer about other mistakes that this query can contains.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently trying to code my own JS drag and drop script (out
I am trying to reuse Apple's Speak Here sample code in my own iPhone
I'm a beginner and trying to generate as much of my own code as
I am having an issue converting type. I was trying code like this (minimal,
I´m trying to code a tooltip (Yes I know, I have my reasons to
I am trying to code TDD style in PHP and one of my biggest
I am trying to code a flowchart generator for a language using Ruby. I
I've been trying to code a Perl script to substitute some text on all
I'm trying to code what I think is a fairly routine AJAX pattern using
I was trying to code along with the PDC2008 Intro to F# video .

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.