How to make a fancy mysql join that can join three tables and detect if one table DOESNT have my item <p>php mysql query I have multiple linked tables - I also have a table that only creates and entry if certian conditions exist so I would like to add that into my query to avoid having to go through thousands of query searches looking for this special case</p> <p>here is my current query</p> <pre><code>$query = "SELECT a.UUID FROM contract a INNER JOIN geoPoint b ON a.customer_UUID = b.customerUUID WHERE b.garcom_UUID = '$garbCom' AND b.city_UUID = '$city'"; </code></pre> <p>I then go through each item that was returned (in the thousands)</p> <pre><code>while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $sentdata = getothertable($row['UUID']); //checks if the item is in the table $sent = $sentdata ['senttoGarcom']; if($sent == 0) //if it wasn't found add it to my list { array_push($Contracts,$row['UUID']); } } </code></pre> <p>instead of all that I would like to just make it one query - pseduo code something like this</p> <pre><code> $query = "SELECT a.UUID FROM contract a INNER JOIN geoPoint b ON a.customer_UUID = b.customerUUID INNER JOIN contract_sales c ON a.UUID = c.contractUUID WHERE b.garcom_UUID = '$garbCom' AND b.city_UUID = '$city' AND c.DOESNOTEXIST"; </code></pre> <p>this way I dont have to return thousands I will only be returned the few that are not yet in the contract_sales table and I can go about my business...</p> <p>Appreciate any help!</p>