Mysql 组合来自多个表的数据
我有两张桌子如下 表A asMysql 组合来自多个表的数据,mysql,sql,mariadb,pivot-table,Mysql,Sql,Mariadb,Pivot Table,我有两张桌子如下 表A as col1 col2 col3 col4 1 2 3 4 101 201 301 401 还有一张桌子——表B col1 col2 col3 col4 1 2 3 4 结果表C或结果应为 结果 col1 col2 col3 col4 col5 col6 col7 col8 1 2 3 4 1 2 3 4 101 201 301 401 null null
col1 col2 col3 col4
1 2 3 4
101 201 301 401
还有一张桌子——表B
col1 col2 col3 col4
1 2 3 4
结果表C或结果应为
结果
col1 col2 col3 col4 col5 col6 col7 col8
1 2 3 4 1 2 3 4
101 201 301 401 null null null null
基本上,我们希望在任何可用的地方保存表中的公共行。
我使用的是MYSQL看起来像是所有4列的公共左连接。匹配条件必须明确制定。这看起来像是糟糕的模式设计,但目前太抽象,无法确定是否遵循pivot表标记。
select * from TableA a left join TableB b
on a.col1 = b.col1 and a.col2 = b.col2 and a.col3 = b.col3 and a.col4 = b.col4