title: SQL Server 2008 select top 1 row from multiple tables?
body: <p>I have a table that stores articles, like the example:</p>
  <p>Article table:</p>
  <h3>ID #CategoryID #Text #Date</h3>
  <p>So on the page I have different sections and each section has its own categoryID. For example, sports is 1, news is 2 etc.</p>
  <p>Now I want the possibility to load the latest article from x number of categories. I have an SP that takes an nvarchar with the ID's separated by space.</p>
  <p>So now the question is, how can I select the latest inserted article from the categories in the nvarchar?</p>
  <p>I use Erland Sommerskog's nvarchar-to-table to get the ID's into a table (<a href="http://www.sommarskog.se/arrays-in-sql-2005.html#iter-list-of-integers" rel="nofollow noreferrer">http://www.sommarskog.se/arrays-in-sql-2005.html#iter-list-of-integers</a>)</p>
  <p>Normally I would use something like this to select articles from several categories:</p>
  <pre><code>SELECT TOP 5 ArticleID, Headline, CategoryID, ShortDescription, DatePublished 
  FROM Article 
  WHERE ArticleState = 3 
  AND CategoryID IN (SELECT i.number FROM iter_intlist_to_tbl(@Categories) AS i)
  ORDER BY DatePublished DESC
  </code></pre>
  <p>But how do I only select the last article from each of the categories supplied?</p>