title: SQL query to get greatest distinct date - kind of
body: <p>I have two tables: articles and articletags</p>
  
  <pre><code>articles: id, author, date_time, article_text
  articletags: id, tag
  
  (article.id == articletags.id in a many-to-many relationship)
  </code></pre>
  
  <p>I am after the last time that something was published under each tag. To put it another way, for every tag, look through all the articles it is related to and find the most recent and return that.</p>
  
  <p>eg
  articles:</p>
  
  <pre><code>1, me, 12 Nov, Sometext
  2, me, 13 Nov, Sometext
  3, me, 14 Nov, Sometext
  </code></pre>
  
  <p>article tags</p>
  
  <pre><code>1, foo
  1, bar
  2, foo
  3, bar
  </code></pre>
  
  <p>I want to get back:</p>
  
  <pre><code>foo, 13 Nov
  bar, 14 Nov
  </code></pre>
  
  <p>I can get as far as an inner join and then am stumped. I dont think a DISTINCT clause is what I am after and I am not familiar enough for subqueries to know if that would help.</p>
  
  <pre><code>SELECT date_time, tag 
  FROM articles, articletags
  WHERE articles.id = articletags.id 
  </code></pre>
  
  <p>Is this even possible?</p>