mysql 如何三个表及以上进行全连接(替代full join 两个表的可以)
1条回答 默认 最新
- Java大魔王 2022-09-18 10:18关注
有三张表,table_a, table_b, table_c b中的a_id关联a的id,c中的b_id关联b的id 1.可以用left join union all right join实现两个表的全连接 2.再用子查询中,拼上第三个表 -- a,b,c三个表全连接 select * from( -- a,b两表全连接 SELECT a.id as a_id, b.id as b_id FROM table_a a left join table_b b on a.id = b.a_id union all SELECT a.id as a_id, b.id as b_id FROM table_a a right join table_b b on a.id = b.a_id )t1 left join ( select * from table_c ) c on c.b_id = t1.b_id union select * from( -- a,b两表全连接 SELECT a.id as a_id, b.id as b_id FROM table_a a left join table_b b on a.id = b.a_id union all SELECT a.id as a_id, b.id as b_id FROM table_a a right join table_b b on a.id = b.a_id )t2 right join ( select * from table_c ) c on c.b_id = t2.b_id;
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥20 西门子S7-Graph,S7-300,梯形图
- ¥50 用易语言http 访问不了网页
- ¥50 safari浏览器fetch提交数据后数据丢失问题
- ¥15 matlab不知道怎么改,求解答!!
- ¥15 永磁直线电机的电流环pi调不出来
- ¥15 用stata实现聚类的代码
- ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效
- ¥15 悬赏!微信开发者工具报错,求帮改