查询returns null 如果有child table 有空记录

Query returns null If any child table has null record

PostgreSQL 新手,在单个查询中获取 parent 和 child table 数据。问题是如果 child table 中的任何一个有空记录,则整个查询 returns 为空。

SELECT r.resume_id,
       r.resume_name,
       r.updation_date, 
       edu.education_id, 
       edu.title, 
       edu.institute,
       exp.experience_id, 
       exp.designation, 
       exp.company_name, 
       exp.start_date, 
       skill.skill_id, 
       skill.skill_name 
  FROM user_resume r, 
       user_education edu, 
       user_experience exp, 
       user_skill skill 
 WHERE edu.resume_id = r.resume_id AND 
       exp.resume_id = r.resume_id AND 
       skill.resume_id = r.resume_id AND 
       r.resume_id = 1592570

这是我在这种情况下的查询,给定的简历在经验 table 中没有记录,结果它 returns 为空,如果我删除具有经验 table 的连接,然后它 returns 记录。

简历中的更多内容table,我也有这些Boolean字段,如果child table (experience, education or skill table) 没有相关记录,则为假. education_missing, experience missing, skill missing

FROM user_resume r
    ,user_education edu
    ,user_experience exp
    ,user_skill skill

is 左内连接 - 这是预期的行为...

FROM user_resume r
LEFT OUTER JOIN user_education edu on COLUMNS
LEFT OUTER JOIN user_experience exp on COLUMNS
LEFT OUTER JOIN user_skill skill on COLUMNS

改为

这会奏效。 LEFT OUTER JOIN 将为您提供 resume table 中的详细信息,并且 child table.

的列中将为 NULL
SELECT r.resume_id,
   r.resume_name,
   r.updation_date, 
   edu.education_id, 
   edu.title, 
   edu.institute,
   exp.experience_id, 
   exp.designation, 
   exp.company_name, 
   exp.start_date, 
   skill.skill_id, 
   skill.skill_name 
 FROM user_resume r 
  LEFT OUTER JOIN user_education edu ON r.resume_id = edu.resume_id
  LEFT OUTER JOIN user_experience exp ON r.resume_id = exp.resume_id
  LEFT OUTER JOIN user_skill skill  ON  r.resume_id = skill.resume_id 
 WHERE 
   r.resume_id = 1592570