我有两张桌子,
Table: Person
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| PersonId | int |
| FirstName | varchar |
| LastName | varchar |
+-------------+---------+
PersonId is the primary key column for this table.
和
Table: Address
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| AddressId | int |
| PersonId | int |
| City | varchar |
| State | varchar |
+-------------+---------+
AddressId is the primary key column for this table.
我想为报告编写SQL查询,该报告为Person表中的每个人提供以下信息,无论每个人都有一个地址:
FirstName, LastName, City, State
# Write your MySQL query statement below
SELECT Person.FirstName, Person.LastName, Address.City, Address.State
FROM Person
INNER JOIN Address ON Person.PersonId=Address.PersonId;
由于某种原因,join返回空数据。请给出提示而不是解决方案。
答案 0 :(得分:1)
考虑到“无论是否有地址”短语,您正在请求LEFT JOIN。
您要求提示,而不是解决方案,因此我只留下指向a Wikipedia article on SQL Joins的链接,指向正确的方向。