Hi
I am new to SQL and are faced with my first complex query.
I would appreciate if someone could help me with the syntax for the following query:
I have two tables: People & Pets
Here are the columns for the People table:
ID int(11)
Name varchar(20)
Dogs varchar(255)
Cats varchar(255)
Here are the columns for the Pets table:
ID int(11)
Name varchar(255)
Here is how people are related to pets:
The Dogs column is a camma-delimited list of all the dogs IDs that the person owns.
The Cats column is a camma-delimited list of all the cats IDs that the person owns.
If the following row exists in the People table:
ID = 1
Dogs = 1,2,
Cats = 4,5,
It means that person 1 has two dogs (the dogs IDs are 1 & 2) and two cats (the cats IDs are 4 & 5).
Here is what I am trying to do:
extractd all the people who have a dog, and sort the list by the dog name.
I would appreciate any help.
If someone thinks that a better arrangement for the tables is in order, please let me know. I am still learning.
thanks in advance