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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:43:43+00:00 2026-06-10T15:43:43+00:00

i cant work out how to get this subquery working to get the latest

  • 0

i cant work out how to get this subquery working to get the latest date for the row.

SELECT Thread_Heading.*, Thread_Articles.*, Thread_ArticlesPost.* 
FROM Thread_Heading 
LEFT JOIN Thread_Articles 
    ON Thread_Articles.Thread_Article_Head_id=Thread_Heading.Thread_Head_id 
LEFT JOIN 
(
    SELECT Thread_ArticlesPost.* 
    FROM Thread_ArticlesPost 
    ORDER BY Thread_ArticlePost_DT DESC
) Thread_ArticlesPost 
    ON  Thread_ArticlesPost.Thread_ArticlePost_Article_id=Thread_Articles.Thread_Article_id  
WHERE Thread_Head_Level = '5' 
GROUP BY Thread_Heading.Thread_Head_id 
ORDER BY Thread_ArticlePost_DT DESC

I need to order the article post date by the latest post for each Thread article.
Fairly new to sql and php i just cant work this one out any help would be appreciated.

T

ABLE: Thread_Heading | 
Thread_Head_id
Thread_Head_Name
Thread_Head_Type
Thread_Head_Creator
Thread_Head_Date
Thread_Head_Level

TABLE: Thread_Articles | 
Thread_Article_id
Thread_Article_Head_id
Thread_Article_Creator
Thread_Article_DT
Thread_Article_Level
Thread_Article_Type
Thread_Article_Title

TABLE: Thread_ArticlesPost | 
Thread_ArticlePost_id
Thread_ArticlePost_Head_id
Thread_ArticlePost_Article_id
Thread_ArticlePost_Creator
Thread_ArticlePost_DT
Thread_ArticlePost_Level
Thread_ArticlePost_Type
Thread_ArticlePost_Title
Thread_ArticlePost_Content

I need to display the date like so:

Head Name | Article title | ORDER BY LATEST ArticlePost DT | ArticlePost Creator

The reason i used left joins was to get the left data even if there are no article or article replys.

Appreciate the help.

Have used this to display data Thanks to Blue

SELECT *
FROM
( SELECT th.Thread_Head_Name,
ta.,
tp1.maxdate,
tp2.

FROM Thread_Heading th
LEFT JOIN Thread_Articles ta
ON th.Thread_Head_id = ta.Thread_Article_Head_id
LEFT JOIN
(
SELECT max(Thread_ArticlePost_DT) maxDate,
Thread_ArticlesPost.*
FROM Thread_ArticlesPost
GROUP BY Thread_ArticlePost_Article_id
) tp1
ON tp1.Thread_ArticlePost_Article_id=ta.Thread_Article_id
LEFT JOIN Thread_ArticlesPost tp2
ON tp1.Thread_ArticlePost_Article_id = tp2.Thread_ArticlePost_Article_id
AND tp1.maxdate = tp2.Thread_ArticlePost_DT
WHERE th.Thread_Head_Level = ‘5’
ORDER BY tp1.maxdate DESC) m
GROUP BY Thread_Head_Name
ORDER BY Thread_ArticlePost_DT 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-06-10T15:43:45+00:00Added an answer on June 10, 2026 at 3:43 pm

    Without seeing your full table schemas you will want do something similar to this:

    SELECT th.*, ta.*, tp.* 
    FROM Thread_Heading th
    LEFT JOIN Thread_Articles ta
        ON th.Thread_Head_id = ta.Thread_Article_Head_id
    LEFT JOIN 
    (
        SELECT max(Thread_ArticlePost_DT) maxDate, Thread_ArticlesPost.* 
        FROM Thread_ArticlesPost 
        GROUP BY Thread_ArticlePost_Article_id
    ) Thread_ArticlesPost tp
        ON  tp.Thread_ArticlePost_Article_id=ta.Thread_Article_id  
    WHERE Thread_Head_Level = '5' 
    GROUP BY th.Thread_Head_id 
    ORDER BY tp.maxdate DESC
    

    Based on your edit the following should return the data you want:

    SELECT th.Thread_Head_Name, 
      ta.Thread_Article_Title,
      tp1.maxdate,
      tp2.Thread_ArticlePost_Creator
    FROM Thread_Heading th
    LEFT JOIN Thread_Articles ta
        ON th.Thread_Head_id = ta.Thread_Article_Head_id
    LEFT JOIN 
    (
        SELECT max(Thread_ArticlePost_DT) maxDate, 
          Thread_ArticlesPost.Thread_ArticlePost_Article_id
        FROM Thread_ArticlesPost 
        GROUP BY Thread_ArticlePost_Article_id
    ) tp1
      ON  tp1.Thread_ArticlePost_Article_id=ta.Thread_Article_id  
    LEFT JOIN Thread_ArticlesPost tp2
      ON tp1.Thread_ArticlePost_Article_id = tp2.Thread_ArticlePost_Article_id
      AND tp1.maxdate = tp2.Thread_ArticlePost_DT 
    WHERE th.Thread_Head_Level = '5' 
    ORDER BY tp1.maxdate DESC
    

    Edit #2, based on your comments, I think the below query should resolve any remaining issues:

    SELECT th.Thread_Head_id,
      th.Thread_Head_Name,
      ta.Thread_Article_Title,
      tp.Thread_ArticlePost_Creator,
      tap.MaxPostDate
    FROM Thread_Heading th 
    LEFT JOIN
    (
      SELECT max(ta.Thread_Article_DT) MaxArticleDate, 
        ta.Thread_Article_Head_id,
        max(tp.Thread_ArticlePost_DT) MaxPostDate
      FROM Thread_Articles ta
      LEFT JOIN Thread_ArticlesPost tp
        ON ta.Thread_Article_id = tp.Thread_ArticlePost_Article_id
      GROUP BY Thread_Article_Head_id
    ) tap
      ON th.Thread_Head_id = tap.Thread_Article_Head_id 
    LEFT JOIN Thread_Articles ta
      ON tap.Thread_Article_Head_id = ta.Thread_Article_Head_id
      AND tap.MaxArticleDate = ta.Thread_Article_DT
    LEFT JOIN Thread_ArticlesPost tp
      ON tap.MaxPostDate = tp.Thread_ArticlePost_DT
    WHERE th.Thread_Head_Level = '5'
    ORDER BY MaxPostDate desc
    

    See SQL Fiddle With Demo

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

Sidebar

Related Questions

I got this. But i can't seem to work out how to get the
This is fairly simple but I cant work it out. I'm building a wordpress
This seems in my head like it should work but I cant figure out
I just cant get this working. I tried using the code below with onTouchEventand
I cant get this script to work, $users should hold the array data we
I cant for the life of me figure out why this doesn't work: javascript:
I can't work out how to get the mysql client to return the number
I can't seem to figure out how to get dependency injection to work in
I really can't work out how to best do this, I can do fairly
I can't believe I can't work out how to do this but what can

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.