我有两张 table ,
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;
由于某种原因,连接返回空数据。请给出提示而不是解决方案。
最佳答案
考虑到“无论是否有地址”短语,您正在请求 LEFT JOIN。
您请求的是提示,而不是解决方案,因此我将仅留下指向 a Wikipedia article on SQL Joins 的链接这应该会为您指明正确的方向。
关于mysql - 连接返回空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46756398/