When something like “p2” is placed after the table name in a query (or JOIN), p2 becomes an alias for that table.
Even though you have two queries for the same table, the alias sorta treats the second reference to the Pets table like it’s a separate table so the WHERE clause does not get confused with things like Pets.PetType = Pets.PetType. So now Pets.PetType = p2.PetType is not pointing at the same column of the same record in the same table, if that makes sense.