Results 1 to 2 of 2
Apr 24, 2004, 22:50 #1
- Join Date
- Mar 2004
- united states
- 0 Post(s)
- 0 Thread(s)
a newbie question regarding data selection
I am beginning to learn SQL and I am stuck trying to perform a simple query. Here are my 3 tables:
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
Apr 25, 2004, 01:42 #2Originally Posted by davidklonski
SELECT Ownership.Person_ID FROM Ownership LEFT JOIN Pets ON Ownership.Pet_ID=Pets.ID WHERE Pets.Type NOT LIKE 'Dog'
Here's another version that returns a table that lists the owner ID, owner name and the type of the pet she/he has. You can use this to test that your query really returns the right results:
SELECT People.ID AS Owner_ID, People.Name AS Owner_Name, Pets.Type AS Pet_type FROM People LEFT JOIN Ownership ON People.ID=Ownership.Person_ID LEFT JOIN Pets ON Ownership.Pet_ID=Pets.ID WHERE Pets.Type NOT LIKE 'Dog'
Last edited by itsyM; Apr 25, 2004 at 02:14.