我有两张 table ,如下所示......
table1
league, date
table2
league, team
我需要做的是当联赛相互匹配时获得所有可能的组合。
例如,在表1中我将有..
Bel1, 39319
Bel1, 39320
Ita1, 39321
例如表2..
Bel1, Anderlecht
Bel1, Bergen
Bel1, Dender
输出必须给我..
Bel1, 39319, Anderlecht
Bel1, 39319, Bergen
Bel1, 39319, Dener
Bel1, 39320, Anderlecht
Bel1, 39320, Bergen
Bel1, 39320, Dener
这可能吗?我曾尝试在 Excel 中完成此操作,但对于我需要处理的数据量而言,它将超过一百万行并且非常耗时,因此我希望我可以在 MySQL 中完成此操作。
最佳答案
这称为交叉连接
。您可以将其用作:
select t1.*, t2.*
from table1 t1 cross join
table2 t2;
但是,我怀疑您确实想要定期加入:
select t1.*, t2.col1
from table1 t1 inner join
table2 t2
on t1.col1 = t2.col1;
您的示例数据没有 'Ita1'
的输出,这表明您确实需要匹配。
关于php - MySQL 两个表的 ALL 组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24467570/