title: Mysql max date within a subquery
body: <p>i cant work out how to get this subquery working to get the latest date for the row.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>
  
  <p>T</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I need to display the date like so:</p>
  
  <pre><code>Head Name | Article title | ORDER BY LATEST ArticlePost DT | ArticlePost Creator
  </code></pre>
  
  <p>The reason i used left joins was to get the left data even if there are no article or article replys.</p>
  
  <p>Appreciate the help.</p>
  
  <p>Have used this to display data Thanks to Blue</p>
  
  <p>SELECT *<br>
  FROM<br>
      ( SELECT th.Thread_Head_Name,<br>
        ta.<em>, 
        tp1.maxdate,
        tp2.</em>
      FROM Thread_Heading th 
      LEFT JOIN Thread_Articles ta 
      ON th.Thread_Head_id = ta.Thread_Article_Head_id 
      LEFT JOIN<br>
      ( 
      SELECT max(Thread_ArticlePost_DT) maxDate,<br>
          Thread_ArticlesPost.* 
          FROM Thread_ArticlesPost
          GROUP BY Thread_ArticlePost_Article_id
      ) tp1 
          ON  tp1.Thread_ArticlePost_Article_id=ta.Thread_Article_id<br>
      LEFT JOIN Thread_ArticlesPost tp2 
          ON tp1.Thread_ArticlePost_Article_id = tp2.Thread_ArticlePost_Article_id 
        AND tp1.maxdate = tp2.Thread_ArticlePost_DT<br>
      WHERE th.Thread_Head_Level = '5'
      ORDER BY tp1.maxdate DESC) m 
  GROUP BY Thread_Head_Name
  ORDER BY Thread_ArticlePost_DT DESC</p>