Mysql 若特定列为null,则In联接中的结果查询不会返回整行

Mysql 若特定列为null,则In联接中的结果查询不会返回整行,mysql,sql,database,database-design,Mysql,Sql,Database,Database Design,我正在尝试从多个表中获取记录。如果db中针对特定id的“im.path”列为null,则在结果中跳过整行 我想知道,如果image没有针对特定id退出,那么结果是,它会显示image path列为空的行 我的问题如下 select distinct p.person_id as p_id,i.current_status,p.*, im.path from invitation i join person p on i.person_id=p.person_id join user u on

我正在尝试从多个表中获取记录。如果db中针对特定id的“im.path”列为null,则在结果中跳过整行

我想知道,如果image没有针对特定id退出,那么结果是,它会显示image path列为空的行

我的问题如下

select distinct p.person_id as p_id,i.current_status,p.*, im.path from invitation i 
join person p on i.person_id=p.person_id
join user u on p.person_id=u.person_id
join image im on u.user_id=im.entity_id
where sender_account_id=40 or i.person_id=40 and invitation_category_id=1
在本例中,如果im.path列为空,则跳过整个记录,这是我不希望看到的

提前谢谢

SELECT distinct p.person_id as p_id, i.current_status, p.*, im.path 
FROM invitation i 
INNER JOIN person p on i.person_id=p.person_id
INNER JOIN user u 
 on p.person_id=u.person_id
LEFT join image im 
  on u.user_id=im.entity_id
WHERE (sender_account_id=40 
   or i.person_id=40)
 and invitation_category_id=1
我也怀疑在这里没有()或语句;所以我加了它们。 此外,在不知道发件人和邀请类别ID所在位置的情况下,他们可能会不适当地限制来自左联接的结果。那么发送者帐户和邀请类别ID在哪个表中呢


是解释连接类型的一个很好的链接。

使用外部连接(左、右或完全外部连接,具体取决于情况)。谢谢亲爱的,我使用左连接得到了结果