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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:47:00+00:00 2026-05-18T08:47:00+00:00

I am using this query to print out a forum board and all it’s

  • 0

I am using this query to print out a forum board and all it’s sub forums. What happens, as may be expected, is that all posts in all threads belonging to that forum are displayed. What I would like to happen is only the first post from each thread is displayed along with the forum title.

Query:

SELECT tf_threads.*, tf_posts.* 
    FROM tf_threads INNER JOIN tf_posts 
    ON tf_threads.thread_id=tf_posts.thread_id 
        AND tf_threads.parent_id=54 ORDER BY tf_posts.date ASC

Please note the parent_id field is given a variable in the real query.

So. If I make sense, can anyone help me out as to what query to write to only select the first post from each thread?

If there are no simple(ish) answers, how could I do it if I used a post number field in the second table, for example, the first post in thread has number 1, second post has number 2, etc. If I use this method, I’d obviously only like to select posts with a count number field of 1. I could just expand the original query with a AND post_number=1 right?

Thanks for reading,

James

  • 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-18T08:47:00+00:00Added an answer on May 18, 2026 at 8:47 am

    Something like this?

    http://murrayhopkins.wordpress.com/2008/10/28/mysql-left-join-on-last-or-first-record-in-the-right-table/

    Edit: I think that it has to be something like this, but I’m also not an SQL expert:

    SELECT tf_threads.*, tf_posts_tmp.*
    FROM tf_threads
    LEFT JOIN (SELECT p1.*
               FROM tf_posts as p1
               LEFT JOIN tf_posts AS p2
               ON p1.postid = p2.postid AND p1.date < p2.date) as tf_posts_tmp
    ON (tf_threads.thread_id=tf_posts_tmp.thread_id)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When using this SQL query: Select * from table_name what happens if the name
I want DBSession.query(Article).group_by(Article.created.month).all() But this query can't using How do I do this using
I have this query that inserts rows, using a subquery like so: INSERT INTO
I would like to be able to print out all results for a query
I am using this query: SELECT DISTINCT pat.PublicationID FROM dbo.PubAdvTransData AS pat INNER JOIN
Currently, I am using this query, which does a pretty good job of finding
I am trying to return voice messages from a database using this query :
I'm using this SQL query to create an index: $query = CREATE INDEX id_index2
I would like to turn this query to regular inline sql without using stored
The code we're using is straightforward in this part of the search query: myCriteria.Add(

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.