带有空值/空值的MySQL JOIN不返回任何结果

rle*_*mon 3 mysql null join

我试图可选地返回一些值(如果它们存在),如果没有返回该组的其余部分.

SELECT people.first_name, countries1.name AS "Country1" 
FROM addressbook_people AS people
JOIN root_countries AS countries1 ON people.country1 = countries1.id
Run Code Online (Sandbox Code Playgroud)

在某些情况下,没有为people.country1提供任何值,
但是如果没有提供任何结果.

当people.country1中没有值时,如何重新构造此查询以仍返回people.first_name?

glg*_*lgl 5

做就是了

SELECT people.first_name, countries1.name AS "Country1" 
FROM addressbook_people AS people
LEFT JOIN root_countries AS countries1 ON people.country1 = countries1.id
Run Code Online (Sandbox Code Playgroud)

这将导致返回表NULL的各个字段root_countries.