我有一个使用MySQL连接的场景,请看下面给出的两个表
Table1:
id A B
1 10 25
2 13 24
3 15 20表2:
id C D
2 12 21
3 10 18
4 13 23我的问题是在a中连接这些表,它返回两个表中的所有行和相应值
Table1 JOIN Table2:
id A B C D
1 10 25 null null
2 13 24 12 21
3 15 20 10 18
4 null null 13 23我认为我们可以使用完全的外部连接来实现这一点。但在MySQL 5.7+中,不支持完全联接。我搜索了很多类似的问题。但是所有人都在谈论使用联合的左连接和右连接。这个解决方案对我没有帮助,因为我总共有7个这样的表。我需要以这种方式从每个表中获取所有数据。因此,如果我使用带有union的left和right join,我的查询将变成一个巨大的查询。那么,有没有其他方法可以得到这个结果呢?
发布于 2019-03-19 14:07:52
对UNION ALL使用left和rigt join
select a.id,A,B, C, D
from table1 a left join table2 b n a.id=b.id
union
select a.id,A,B, C, D
from table1 a right join table2 b n a.id=b.idhttps://stackoverflow.com/questions/55234591
复制相似问题