Mysql 左连接 多个字段

当要进行两个表的字段左连接时只要操作两个左连接即可

一个表 team: 

id name

1  张三

2  李四

3  王五

一个match:

 mid(主键)  id1(第一个编号)  id2(第二个编号

1                  1                           2

2                  2                           3

3                  3                           2

要查询的表是

mid id1 id1name id2 id2name

1      1      张三        2      李四 

2      2      李四        3      王五 

3      3      王五        1      张三 

​
SELECT match.mid,match.id1,team1.name,match.id2,team2.name from match left join team as
 team1 on team1.id = match.id1 left join team as team2 on team2.id = match.id2;

​

表的名字不能有重复的 否则会报错1066 主要为 SQL 语句中出现了非唯一的表或别名。

多表查询类似

    原文作者:Mr_Right林
    原文地址: https://blog.csdn.net/Mr_Right_zwu/article/details/102846890
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞