1 题目描述
2 解题思路
2.1 方法1:不用JOIN
SELECT
FirstName,
LastName,
(SELECT City
FROM Address a
WHERE a.PersonId=p.PersonId) as City,
(SELECT State
FROM Address a
WHERE a.PersonId=p.PersonId) as State
FROM Person p
如果 a.PersonId=p.PersonId不成立,那么select返回的就是NULL,也满足语义条件。
2.2 方法2 外连接
外连接知识可以看数据库笔记——数据模型_刘文巾的博客-CSDN博客 3.10节
SELECT FirstName, LastName, City, State
FROM Person left join Address
ON Person.PersonId = Address.PersonId