[英]Join two tables or select queries in MySQL
I need to join two tables and get the output as i stated below, 我需要连接两个表并获得如下所述的输出,
Here my problem is I couldn't inner join the two tables and get the output since it refers the same column name for team1 and team2 (Which will look like "select ct.teamname,ct2.teamname from clm_schedule cs" where it gives me an error). 在这里,我的问题是我无法内部连接这两个表并获得输出,因为它为team1和team2引用了相同的列名(这看起来像是“从clm_schedule cs中选择ct.teamname,ct2.teamname”,它为我一个错误)。 I can do it in two separate queries like below,
我可以在如下两个单独的查询中进行操作,
select ct.teamname as team1 from clm_schedule cs inner join clm_team ct on ct.teamid = cs.team1
select ct2.teamname as team2 from clm_schedule cs2 inner join clm_team ct2 on ct2.teamid = cs2.team2
But I couldn't join it to get a single resultset. 但是我无法加入以获得单个结果集。 Please suggest me a way.
请给我建议一种方法。
You should be able to do this: 您应该可以执行以下操作:
SELECT ct1.teamname as team1 ,ct2.teamname as team2
FROM clm_schedule cs
LEFT JOIN clm_team AS ct1
ON ct1.teamid = cs.team1
LEFT JOIN clm_team AS ct2
ON ct2.teamid = cs.team2;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.