Actually you still want to use a join, just an OUTER join instead of an INNER one. With an OUTER join, you can get all the rows that match as well as rows where it doesn't match: http://en.wikipedia.org/wiki/Join_(SQL)#Left_outer_join In the example there, DepartmentID 36 is present in the `Employee` table but not in the `Department` table so you get NULL for the `Department` data. Then it's just a matter of checking for NULL. Remember that you can't do "WHERE DepartmentID = NULL" because that will always end up being TRUE (can't use regular comparisons with NULL), you have to use "WHERE DepartmentID IS NULL". -TG ----- Original Message ----- From: <jd.pillion@xxxxxxxxx> To: <php-general@xxxxxxxxxxxxx>, <php-db@xxxxxxxxxxxxx> Date: Wed, 3 Oct 2007 05:21:06 -0500 Subject: [PHP] the opposite of a join? > I have a company table and a contacts table. In the contacts table, there > is a field called "companyID" which is a link to a row in the company table. > > > > What is the easiest way to query the company table for all the company rows > whose ID is NOT linked to in the contact table? Basically, the opposite of a > join? > > > > Thanks > > > > J > > > > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php