title: SQL Server Select Top Within Subsets?
body: <p>I have this data:</p>
  
  <pre><code>Create Table #Some ( ForeignId Int , SubValue UniqueIdentifier , WasRead Bit)
  Insert Into #Some Values ( 1 , 'ADEE70A8-E804-4A0C-93AD-00CCCB3DA7DA' , 0 )
  Insert Into #Some Values ( 1 , '024EDED5-744B-497A-BFB8-06A0C62DE0AE' , 0 )
  Insert Into #Some Values ( 1 , 'C3F255F9-3648-4D8D-8D84-0951BD2D0551' , 0 )
  Insert Into #Some Values ( 1 , '25CE8E67-A263-409E-8E7F-1A814EF76524' , 0 )
  Insert Into #Some Values ( 2 , '1B339D13-B580-4660-9642-0C0FA9C84D14' , 0 )
  Insert Into #Some Values ( 2 , '579C5BD3-EE3A-4789-A57B-0FAD0F7227A2' , 0 )
  Insert Into #Some Values ( 3 , '31D1E0F2-5F8A-451B-8114-14DB685E9F53' , 0 )
  Insert Into #Some Values ( 3 , '52347A60-4156-401F-8570-15554DD905EF' , 0 )
  Insert Into #Some Values ( 3 , '6ECD072E-BC43-4A4C-AACD-1A6C256DCFDE' , 0 )
  Insert Into #Some Values ( 3 , '3264625D-94CE-4798-9E4B-2672EDE496BC' , 0 )
  </code></pre>
  
  <p>I need to select the first three rows for each ForeignId, update their WasPolled value to 1, and emit multiple result sets, but the total size for all sets cannot be more than 8:</p>
  
  <p>set:</p>
  
  <pre><code>1 , 'ADEE70A8-E804-4A0C-93AD-00CCCB3DA7DA' 
  1 , '024EDED5-744B-497A-BFB8-06A0C62DE0AE' 
  1 , 'C3F255F9-3648-4D8D-8D84-0951BD2D0551' 
  </code></pre>
  
  <p>set:</p>
  
  <pre><code>2 , '1B339D13-B580-4660-9642-0C0FA9C84D14' 
  2 , '579C5BD3-EE3A-4789-A57B-0FAD0F7227A2' 
  </code></pre>
  
  <p>set:</p>
  
  <pre><code>3 , '31D1E0F2-5F8A-451B-8114-14DB685E9F53' 
  3 , '52347A60-4156-401F-8570-15554DD905EF' 
  3 , '6ECD072E-BC43-4A4C-AACD-1A6C256DCFDE' 
  </code></pre>