title: SQL Server 2000: How to get top 10 for each distinct field. A loop Maybe?
body: <p>I have the following table</p>
  
  <pre><code>MyTable
    ID
    MessageType
    MessageDate
    MessageBody
  </code></pre>
  
  <p>The table is a few million rows but there are only 100 unique MessageType in it. </p>
  
  <p>What I need is a sample of each MessageType (must include at least MessageType and MessageBody), but I can't do a <code> DISTINCT</code> as that only gets me the MessageType column. </p>
  
  <p>I am thinking something like </p>
  
  <pre><code>SELECT TOP 5 *
   FROM MyTable
   WHERE MessageType IN (SELECT DISTINCT MessageType FROM MyTable)
  </code></pre>
  
  <p>I know this doesn't work as it just me the top 5, but I am not sure how to make SQL loop through this.</p>
  
  <p>Thanks for any help     </p>