title: How to Delete Top(N) rows with an inner join?
body: <p>I am trying to delete a few rows from two tables using the following query</p>
  
  <pre><code>Delete top(3) ss 
  from stage.SubmitItemData ss 
  INNER JOIN stage.SubmitItems s (NOLOCK) on ss.SubmitItemId = s.SubmitItemId 
  where s.AgencyCode = 'NC0860000' and s.StatusId = 8
  </code></pre>
  
  <p>Where I am stumped is if I remove the parameters <code>s.AgencyCode</code> and <code>s.StatusId</code> the query executes with no issue. However if I add these parameters I get the <code>(0) rows affected.</code> </p>
  
  <p>All I am trying to do is to control the number of records deleted at any given time. Is top(n) not the best approach as it looks as if it requires ordering to work?  Would it be better to create a loop for this type of delete?</p>
  
  <p>Thanks for any suggestions. </p>