title: Delete unmatched records in Access
body: <p>I have a table in an Access database where records may be referenced from either of two other tables. I need to delete records from that table if they are not referenced by either of the others.
  My best solution so far has been to create a subquery to return the id's of the referenced records and to refer to the subquery from a delete query. (The subquery has to be separate because Access does not allow UNION in nested subqueries.)</p>
  
  <p>So ...<br>
  SelectQuery:  </p>
  
  <pre><code>SELECT TableB.id FROM TableB INNER JOIN TableA ON TableB.id = TableA.id  
  UNION  
  SELECT TableC.id FROM TableC INNER JOIN TableA ON TableC.id = TableA.id  
  </code></pre>
  
  <p>DeleteQuery:</p>
  
  <pre><code> DELETE * FROM TableA WHERE id NOT IN (SELECT * FROM SelectQuery)
  </code></pre>
  
  <p>This is excruciatingly slow ... there must be a better way?</p>
  
  <p>I was trying to avoid having to add a boolean '<code>Used</code>' field to TableA ...</p>