Chapter Three – Structured Query Language
© 2018 Pearson Education, Inc. Page 31 of 154
SELECT OwnerLastName, OwnerFirstName, OwnerEmail
FROM PET_OWNER PO JOIN PET_3 P
ON PO.OwnerID = P.OwnerID
WHERE PetType = ‘Cat’;
We can also use DISTINCT to remove duplicate lines:
SELECT DISTINCT OwnerLastName, OwnerFirstName, OwnerEmail
3.39 Answer question 3.36, but use a join using JOIN ON syntax.
Note that in this solution we used the table names instead of aliases so the solution is identical
for all DBMSs except Access (contrast with the solutions to the previous question). Note also
that this query happens to return no duplicates, but in theory it could, in which case DISTINCT
would be required to make it precisely equivalent to question 3.36 (see solutions to the
previous question).
For SQL Server, Oracle, and MySQL:
For Access:
3.40 Answer part (4) of question 3.37, but use joins using JOIN ON syntax.
For Microsoft SQL Server and MySQL:
SELECT DISTINCT OwnerLastName, OwnerFirstName, OwnerEmail
FROM (PET_OWNER as PO JOIN PET_3 as P