| ross perry 2004-04-27, 5:52 pm |
| one way is to create a temp. table of dog owners and then display the people
not in the dog owner table, for example,
drop table if exists dog_owners;
create temporary table dog_owners
select people.name
from people, ownership, pets
where
(pets.type = "dog") and
(pets.id = ownership.pet_id) and
(ownership.person_id = people.id);
select people.name from people
left join dog_owners on people.name = dog_owners.name
where dog_owners.name is null;
drop table if exists dog_owners;
"davidklonski" <davidklonski@fastmail-dot-fm.no-spam.invalid> wrote in
message news:K5mdnfEZC6av_hbdRVn_vQ@giganews.com...
> Hello
>
> I am beginning to learn SQL and I am stuck trying to perform a simple
> query. Here are my 3 tables:
>
> People:
> ID: int(5)
> Name: varchar(255)
>
> Pets:
> ID: int(5)
> Name: varchar(255)
> Type: varchar(255)
>
> Ownership:
> Person_ID int(5)
> Pet_ID int(5)
>
> The Ownership table makes the connection between a person and a pet.
> I would like to extract the IDs of all the people who
> don't own a pet of type 'dog'. They
> are allowed to own pets of other types of course.
>
> Please help, I am stuck with the mysql manual and going nowwhere
>
> thanks
>
>
>
> ----------------------------------------
> The post originated from PHP Freaks:
> ----------------------------------------
> http://www.phpfreaks.com
> http://www.phpfreaks.com/forums
>
>
|