Task: Text to Code
Input (English): Step 1: For each row in Has_Pet table, find corresponding rows in Student table and in Pets table.
Step 2: find Fname of the results of step 1 whose PetType equals cat.
Step 3: For each row in Pets table, find the corresponding rows in Has_Pet table.
Step 4: find Has_Pet's StuID of the results of step 3 whose PetType equals dog.
Step 5: show the rows that are in both the results of step 2 and the results of step 4
Output (English): SELECT T1.Fname FROM Student AS T1 JOIN Has_Pet AS T2 ON T1.StuID = T2.StuID JOIN Pets AS T3 ON T2.PetID = T3.PetID WHERE T3.PetType = "cat" INTERSECT SELECT T2.StuID FROM Has_Pet AS T2 JOIN Pets AS T3 ON T2.PetID = T3.PetID WHERE T3.PetType = "dog"