title: Delete using where not exists
body: <p>I am trying to delete records that exist in a master file where the account number, which consists of three fields mn_no, sb_no, and dp_no, are not in transaction tables.  Because the account number may be in one or more transaction tables, I need to test for its presence in all.  When I run the following query, MS-SQL returns an incorrect syntax error near a in line 1.</p>
  
  <pre><code>DELETE
  FROM SYACTFIL_SQL a
  WHERE NOT EXISTS (
          SELECT b.mn_no
              ,b.sb_no
              ,b.dp_no
          FROM gltrxhst_sql b
          WHERE a.mn_no = b.mn_no
              AND a.sb_no = b.sb_no
              AND a.dp_no = b.dp_no
          )
      AND NOT EXISTS (
          SELECT b.mn_no
              ,b.sb_no
              ,b.dp_no
          FROM gltrxfil_sql b
          WHERE a.mn_no = b.mn_no
              AND a.sb_no = b.sb_no
              AND a.dp_no = b.dp_no
          )
      AND a.mn_no &lt;&gt; '00000000'
  </code></pre>