I got this in my homework and can’t figure it out, please help.
I have 3 tables:
owners(id, name), breeds(id, type), dogs(id, ownerid, breedid)
Connections:
owners.id = dogs.ownerid AND breed.id = dogs.breedid
My assignment is to find the the owners name whose name is LIKE the breed type.
Example: ‘John Shepherd’ has a ‘german shepherd’, so write his name, because of the match in the naming of the breed type and the owners name.
Tried to solve this like this:
SELECT owners.name
FROM owners, dogs, breed
WHERE owners.name LIKE CONCAT('%', breeds.type, '%')
AND dogs.breedid = breeds.id
AND dogs.ownerid = owners.id;
I know this is faulty because the owner is not called ‘John German Shepherd’.
Is there a way to LIKE this query a way that the answer doesn’t consider the whole breed.type or considers types with multiple words in it?
Dávid Molnár is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.