Re: An small SQL problem
| From: | Brad Bulger | Date: | Sat, 12 Oct 2002 11:31:01 +0000 |
| Subject: | Re: An small SQL problem | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-119731@lists.php.net to get a copy of this message | ||
what database are you using? because the answer is different, depending.
on postgres, for example, which supports subselects, you can do
select * from TableA where FieldA1 not in (select FieldB2 from TableB)
with mysql, there are no subselects, so you'd have to do something like
select TableA.*, TableB.FieldB1
from TableA left join TableB on TableA.FieldA1 = TableB.FieldB1
having FieldB1 is null
PS the one thing that for sure will not work is
select TableA.* from TableA, TableB where TableA.FieldA1 != TableB.FieldB2
that will just give you a cartesian product, returning a copy of
every row in TableA for every row in TableB that doesn't match its key
On Sat, 12 Oct 2002, Christian Ista wrote:
> Hello,
>
> I'm probably sleepy because I can't do a very easy query. :(
>
> I have 2 tables TableA(FieldA1, FieldA2, FieldA3) and TableB(FieldB1,
> FieldB2, FieldB3).
>
> I'd like to see the TableA records (FieldA2) where the FieldA1(Primary
> key) not exist in TableB(FieldB2). I tried "not exists" without success.
>
> Could you help me ?
>
> Christian,
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>