Here is my work for Exercise 6: Select Across Many Tables.
In this exercise, I learned how to select from multiple tables. Using the person, pet, and person_pet tables created previously, we can select all the pets owned by one person.
- This may be a mind blowing weird way to look at data if you already know a language like Python or Ruby. Take the time to model the same relationships using classes and objects then map it to this setup.
In Ruby, person and pet would both be their own classes. A person has a first_name, last_name, id, and age. A pet has an id, name, age, and ‘dead’ status. To show that a person has-a pet, we would add a person_pet property to a person and specify the value as the pet they have.
- Do a query that finds your pets you’ve added thus far.
I’ve only added one pet, Drogon.
- Change the queries to use your person.id instead of the person.name like I’ve been doing.