Re: Joining 2 tables
| From: | Justin Buist | Date: | Fri, 10 Aug 2001 17:41:48 +0000 |
| Subject: | Re: Joining 2 tables | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-11230@lists.php.net to get a copy of this message | ||
select id, name from A where id NOT IN (SELECT tableAid from B where
userid = $userid)
That should do it.
Justin Buist
Trident Technology, Inc.
4700 60th St. SW, Suite 102
Grand Rapids, MI 49512
Ph. 616.554.2700
Fx. 616.554.3331
Mo. 616.291.2612
On Fri, 10 Aug 2001, Scott Gines wrote:
> I am having trouble getting the correct join...here is my scenario.
> I have 2 tables, A and B.
> A looks something like this...
> [id] [name]
> 1 Name1
> 2 Name2
> 3 Name3
>
> B looks like this...
> [userid] [tableAid]
> 1 1
> 1 3
> 2 1
> 2 2
>
> I am looking for a join that will return only the items NOT found in table B
> from table A. In this example, it would return 2/Name2 from table A for
> userid 1.
>
> This is my current statement:
> select id, name from A left join A on A.id=B.tableAid where B.userid=1;
>
> This gives me just the opposite of what I want.
>
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>