BTCWorker
Registered Member
- Apr 8, 2015
- 71
- 7
If anyone can take a look at this and tell me what I am doing wrong, I would surely appreciate it. I am using my textbook and W3schools SQL Tutorials and can't figure out why I keep having issues with these two specific queries...
Question: 335
Write an SQL statement to display the OwnerLastName, OwnerFirstName, and OwnerEmail of any owners of cats. Use a subquery with PET_OWNER and PET_3.
PET_OWNER
PET_3
QUERY:
SELECT OwnerLastName, OwnerFirstName, OwnerEmail
FROM PET_OWNER
WHERE PET_OWNER.OwnerID= (SELECT PET_3.OwnerID FROM PET_3
WHERE Pet_3.Pettype='Cat')
-----
It Returns: Query failed: Subquery returns more than 1 row
Screenshot:
https://gyazo.com/42b58823f433cf1671aef535b3e8e7cf
and the next question is the same as the above but I also have to include the Cat name 'Teddy'..
Screenshot:
https://gyazo.com/a6a13976a6481c0b2fc4256ad5941af2
I appreciate any help I can get here because I am at a lost. I did think about using a 'View' or a 'Join', but not even sure if those would work. I just cannot understand why what I did try will not work. Seems pretty straight forward, but still returns errors no matter what I try. The thing that is most frustrating is that I WANT it to return more than one row..
Question: 335
Write an SQL statement to display the OwnerLastName, OwnerFirstName, and OwnerEmail of any owners of cats. Use a subquery with PET_OWNER and PET_3.
PET_OWNER
| OwnerID | OwnerLastName | OwnerFirstName | OwnerPhone | OwnerEmail |
|---|---|---|---|---|
| 1 | Downs | Marsha | 555-537-8765 | [email protected] |
| 2 | James | Richard | 555-537-7654 | [email protected] |
| 3 | Frier | Liz | 555-537-6543 | [email protected] |
| 4 | Trent | Miles | [email protected] |
PET_3
| PetID | PetName | PetType | PetBreed | PetDOB | PetWeight | OwnerID |
|---|---|---|---|---|---|---|
| 1 | King | Dog | Std. Poodle | 2009-02-27 00:00:00 | 25.5 | 1 |
| 2 | Teddy | Cat | Cashmere | 2010-02-01 00:00:00 | 10.5 | 2 |
| 3 | Fido | Dog | Std. Poodle | 2008-07-17 00:00:00 | 28.5 | 1 |
| 4 | AJ | Dog | Collie Mix | 2009-05-05 00:00:00 | 20.0 | 3 |
| 5 | Cedro | Cat | Unknown | 2007-06-06 00:00:00 | 9.5 | 3 |
| 6 | Wooley | Cat | Unknown | 9.5 | 4 | |
| 7 | Buster | Dog | Border Collie | 2006-12-11 00:00:00 | 25.0 | 4 |
QUERY:
SELECT OwnerLastName, OwnerFirstName, OwnerEmail
FROM PET_OWNER
WHERE PET_OWNER.OwnerID= (SELECT PET_3.OwnerID FROM PET_3
WHERE Pet_3.Pettype='Cat')
-----
It Returns: Query failed: Subquery returns more than 1 row
Screenshot:
https://gyazo.com/42b58823f433cf1671aef535b3e8e7cf
and the next question is the same as the above but I also have to include the Cat name 'Teddy'..
Screenshot:
https://gyazo.com/a6a13976a6481c0b2fc4256ad5941af2
I appreciate any help I can get here because I am at a lost. I did think about using a 'View' or a 'Join', but not even sure if those would work. I just cannot understand why what I did try will not work. Seems pretty straight forward, but still returns errors no matter what I try. The thing that is most frustrating is that I WANT it to return more than one row..