Yoo*_*at 1 sql null join left-join
我需要帮助.
我需要加入两个双打
表格1
Product_Name Content_Type Price
Movie Adult 10
Movie Kids 10
Run Code Online (Sandbox Code Playgroud)
表2
Product_Name Content_Type Rating
Movie Adult A
Movie Kids B
Movie Romance C
Run Code Online (Sandbox Code Playgroud)
我需要加入表格,看起来像这样
期望的输出
Product_Name Content_Type Price Rating
Movie Adult 10 A
Movie Kids 10 B
Movie Romance C
Run Code Online (Sandbox Code Playgroud)
电流输出
Product_Name Content_Type Price Rating
Movie Adult 10 A
Movie Kids 10 B
Movie Romance 10 C
Run Code Online (Sandbox Code Playgroud)
当前查询
select * from table2 left join table1 on table2.Product_Name=table1.Product_Name
Run Code Online (Sandbox Code Playgroud)
实际上,在实际表中,Product_Name有许多值.考虑到这种逻辑,我写了这样的查询,
查找table2中的所有行,在table1中查找匹配项并加入行.如果table2中有一行,但table1中没有行,则只显示table2的值,同时为table1中的相应字段显示Null.
如果您只是加入product_name,则不会获得内容类型为Romance的记录.您还需要加入content_type:
select *
from table2 left join
table1
on table2.Product_Name=table1.Product_Name and
table2.content_type = table1.content_type
Run Code Online (Sandbox Code Playgroud)