如果记录不存在,SQL联接表将显示空字段

如果记录不存在,SQL联接表将显示空字段,sql,join,null,left-join,Sql,Join,Null,Left Join,我需要帮助 我需要参加两个双人赛 表1 Product_Name Content_Type Price Movie Adult 10 Movie Kids 10 表2 Product_Name Content_Type Rating Movie Adult A Movie Kids B Movie Romance C 我需要把这些表连接起

我需要帮助

我需要参加两个双人赛

表1

Product_Name Content_Type Price
 Movie         Adult       10
 Movie         Kids        10
表2

Product_Name Content_Type Rating
 Movie         Adult        A
 Movie         Kids         B
 Movie         Romance      C
我需要把这些表连接起来,这样看起来像这样

期望输出

 Product_Name Content_Type Price Rating
   Movie         Adult      10     A
   Movie         Kids       10     B
   Movie         Romance           C   
电流输出

 Product_Name Content_Type Price Rating
   Movie         Adult      10     A
   Movie         Kids       10     B
   Movie         Romance    10     C 
当前查询

select * from table2 left join table1 on table2.Product_Name=table1.Product_Name 
实际上,在实表中,Product_Name有许多值。 我写这个问题的时候就考虑到了这个逻辑


查找表2中的所有行,在表1中找到匹配项并将这些行合并。如果表2中有一行,但表1中没有行,则只显示表2的值,同时为表1中相应的字段显示Null。

如果您只是在产品名称上加入,则不会获得内容类型为ROMAN的记录。您还需要在内容类型上加入:

select *
from table2 left join
     table1
     on table2.Product_Name=table1.Product_Name and
        table2.content_type = table1.content_type

如果您只加入产品名称,则不会获得内容类型为Romand的记录。您还需要在内容类型上加入:

select *
from table2 left join
     table1
     on table2.Product_Name=table1.Product_Name and
        table2.content_type = table1.content_type

添加并在加入条款中键入内容在加入条款中键入内容Hello非常感谢您的建议很好。您好,非常感谢您的建议很好。