Sample Video Frame

Created by Zed A. Shaw Updated 2026-08-31 20:32:57
 

Exercise 10: Updating Complex Data

In the previous exercise you did a simple UPDATE that changed just one row. In this exercise you'll use sub-select queries again to update the pet table using information from the person and person_pet tables.

View Source file ex10.sql Only

SELECT * FROM pet;

UPDATE pet SET name = 'Zed''s Pet' WHERE id IN (
    SELECT pet.id 
    FROM pet, person_pet, person 
    WHERE 
    person.id = person_pet.person_id AND
    pet.id = person_pet.pet_id AND
    person.first_name = 'Zed'
);

SELECT * FROM pet;

This is how you update one table based on information from another table. There're other ways to do the same thing, but this way is the easiest to understand for you right now.

Previous Lesson Next Lesson

Register for Learn SQL the Hard Way

Register today for the course and get the all currently available videos and lessons, plus all future modules for no extra charge.