Re: the opposite of a join?
| From: | TG | Date: | Wed, 03 Oct 2007 11:30:08 +0000 |
| Subject: | Re: the opposite of a join? | ||
| Groups: | php.db php.general | ||
| Request: | Send a blank email to php-general+get-262673@lists.php.net to get a copy of this message | ||
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@gmail.com>
To: <php-general@lists.php.net>, <php-db@lists.php.net>
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
>
>
>
>
>