title: PHP MYSQL Join Query. SELECT WHERE AND IN OR Logic Error
body: <p>Hey all. I think I have a logic error in my qry. The output is correct but in triplets. I’ve been staring at this for a long time and not seeing it. Can someone shed some light on this? Thanks!!</p>
  
  <p>Also wanted to add this info as well.</p>
  
  <ul>
  <li>$userid = 1</li>
  <li>$UserIDAList = (1,1,6)</li>
  <li>$UserIDBList = (2,3,1)</li>
  </ul>
  
  <p>PHP-Code:</p>
  
  <pre><code>$result  = mysql_query("SELECT TBL_ContactsList.ContactID, TBL_ContactName.FirstName FROM TBL_ContactsList, TBL_ContactName WHERE ((TBL_ContactName.NameID != $userid) AND (TBL_ContactsList.ContactID != $userid)) AND ((TBL_ContactName.NameID IN ($UserIDAList) OR TBL_ContactName.NameID IN $UserIDBList)))");
  
  while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
      printf ("ID: %s  Name: %s", $row[0], $row[1]);
      echo "&lt;br/&gt;";
  }
  </code></pre>
  
  <p>Only the SQL-Query (readability):</p>
  
  <pre><code>SELECT TBL_ContactsList.ContactID, TBL_ContactName.FirstName 
  FROM TBL_ContactsList, TBL_ContactName 
  WHERE ((TBL_ContactName.NameID != $userid) AND (TBL_ContactsList.ContactID != $userid)) 
  AND ((TBL_ContactName.NameID IN ($UserIDAList) OR TBL_ContactName.NameID IN $UserIDBList)))
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>ID: 2 Name: Joe
  ID: 3 Name: Joe
  ID: 4 Name: Joe
  ID: 2 Name: Jimbo
  ID: 3 Name: Jimbo
  ID: 4 Name: Jimbo
  ID: 2 Name: Mike
  ID: 3 Name: Mike
  </code></pre>
  
  <p>EDIT: Here is what I ended up using. (can't figure out indent on here.)  </p>
  
  <p>But now I am missing an entry from the db.  </p>
  
  <p><code>$result = mysql_query("<br>
      SELECT cl.ContactID, cn.FirstName<br>
      FROM TBL_ContactName AS cn<br>
      INNER JOIN TBL_ContactsList AS cl<br>
          ON cl.ContactID = cn.NameID<br>
      WHERE<br>
          cn.NameID != $userid<br>
      AND (<br>
          cn.NameID IN ($UserIDBList) OR cn.NameID IN ($UserIDAList)<br>
      )<br>
  ");
  </code>
  The output looks like this.<br>
  ID: 2 Name: Joe<br>
  ID: 3 Name: Jimbo  </p>
  
  <p>But when I put LEFT JOIN I get this. Close but still missing ID.<br>
  ID: 2 Name: Joe<br>
  ID: 3 Name: Jimbo<br>
  ID: Name: Mike  </p>
  
  <p>Any ideas?? THanks!</p>