Sql 如何连接具有空行的表?
如果合并了表B、表C等,并且每个合并的表可能没有匹配的记录,那么如何返回表A中的所有行Sql 如何连接具有空行的表?,sql,oracle,Sql,Oracle,如果合并了表B、表C等,并且每个合并的表可能没有匹配的记录,那么如何返回表A中的所有行 Row Letter Shelter Food 1 A House Bread 2 B Shed Cheese 3 C Tent Meat 4 D Patio 5 E
Row Letter Shelter Food
1 A House Bread
2 B Shed Cheese
3 C Tent Meat
4 D Patio
5 E
例如:
Table A Table B Table C
Row Letter Row Shelter Row Food
1 A 1 House 1 Bread
2 B 2 Shed 2 Cheese
3 C 3 Tent 3 Meat
4 D 4 Patio
5 E
Row Letter Shelter Food
1 A House Bread
2 B Shed Cheese
3 C Tent Meat
4 D Patio
5 E
结果
Row Letter Shelter Food
1 A House Bread
2 B Shed Cheese
3 C Tent Meat
4 D Patio
5 E
我的查询会根据没有匹配值的每个表减少结果,这意味着该项不存在任何条目。使用
外部联接
Row Letter Shelter Food
1 A House Bread
2 B Shed Cheese
3 C Tent Meat
4 D Patio
5 E
select *
From TableA a
Left Join TableB b on a.Row = b.Row
Left Join TableC c on a.Row = c.Row
即使右表中没有匹配的记录,Left Join也会带来左表中的所有记录检查什么是Left Join/right Join
Row Letter Shelter Food
1 A House Bread
2 B Shed Cheese
3 C Tent Meat
4 D Patio
5 E