title: Is there a better way to write a query for deleting records based on sub queries?
body: <p>I have this query:</p>
  
  <pre><code>DELETE from MailingListTable where Md5Hash in (
     SELECT
        dbo.ListItems.Md5Hash
     FROM dbo.Lists
     INNER JOIN dbo.ListItems ON dbo.Lists.Id = dbo.ListItems.ListId
     where dbo.Lists.IsGlobal = 1
   )
  </code></pre>
  
  <p>The MailingListTable is built dynamically from multiple lists. I then run the above query to remove any list items that are in a global remove list.</p>
  
  <p>It's not horrible on small sets, but larger sets it can take almost 5 to 8 minutes (based on some tests I did). I am curious if there is a better way to write this. I don't believe I can use joins with a delete statement. So that is why I opted for the sub query.</p>
  
  <p>I also tried using <code>EXISTS</code>, but that was much slower. Would it be better to use <code>common-table expressions</code> since I am using SQL Server 2008?</p>