两个 SELECT 语句之间的 MySQL 笛卡尔积

2021-12-17 00:00:00 join select mysql

我想在两个 SELECT 语句之间执行笛卡尔积

I want to perform a cartesian product between two SELECT statements as

SELECT 1, 2     INNER JOIN     SELECT 3, 4 ;

我希望结果是 (1,2) 和 (3,4) 的每个组合,例如:

I expect the result to be every combination of (1,2) with (3,4), like:

1  3
2  3
1  4
2  4

推荐答案

您可以使用 CROSS JOIN 子句

You can use the CROSS JOIN clause

SELECT MyTable1.Col1, MyTable2.Col2
FROM MyTable1
CROSS JOIN MyTable2

其中 MyTable1 有两行包含 1 和 2;MyTable2 有两行包含 3 和 4.

where MyTable1 has two rows containing 1 and 2; and MyTable2 has two rows containing 3 and 4.

相关文章