title: How to do a foreach type query in mysql, comparing each row with several rows in another table?
body: <p>I need to check each entryForm row's name and check if this name occurs in a list of SiteContacts where the .siteid and entryForm.siteid match.  (There is no point checking an entryForm row where the sites don't match.) I need to be left with the entryForms not matching. </p>
  
  <p>An entryForm has one siteContact, a siteContact can have many entryForms.</p>
  
  <pre><code>select * from siteContacts, entryForm 
  where siteContacts.siteid=entryForm.siteid 
  and entryForm.name not like concat('%',siteContacts.lastname, '%')
  </code></pre>
  
  <p>siteContacts is a table like this:</p>
  
  <pre><code>id  |   lastname     |  siteid  
  ===============================
  7   |   Cooper       |   2
  8   |   Hofstadter   |   2
  9   |   Wolowitz     |   3
  10  |   Koothrappali |   3
  </code></pre>
  
  <p>entryForms is a table like this:</p>
  
  <pre><code>id  |   name           |  siteid  
  ==================================
  1   |   Sheldon Cooper |   2
  2   |   L. Hofstadter  |   2
  3   |   Penny          |   3
  4   |   Wolowitz       |   3
  5   |   Dr Hofstadter  |   2
  </code></pre>
  
  <p>The result should be Penny :</p>
  
  <pre><code>3   |   Penny          |   3
  </code></pre>
  
  <p>but it's not....</p>