Description:
Given Table: Person and Table: Address
Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people:
FirstName, LastName, City, State
- 考点:多表查询。
- JOIN 用于根据两个或多个表中的列之间的关系,从这些表中查询数据;
- INNER JOIN 在表中存在至少一个匹配时,关键字返回行(与JOIN结果等价);
- LEFT JOIN 关键字会从左表 (table_name1) 那里返回所有的行,即使在右表 (table_name2) 中没有匹配的行;
- RIGHT JOIN 关键字会右表 (table_name2) 那里返回所有的行,即使在左表 (table_name1) 中没有匹配的行;
- 只要其中某个表存在匹配,FULL JOIN 关键字就会返回行。
select p.FirstName,p.LastName,a.City,a.State from Person p left join Address a on p.PersonId=a.PersonId