[英]MySQL join two Tables to n:m Relation
I have two tables (Table 1 and Table 2) and I want to create a table (Table 3) with the ID's. 我有两个表(表1和表2),我想用ID创建一个表(表3)。 So to speak an to m relationship table.
可以说是一个与m的关系表。
Table 1
1 Mark
2 George
3 David
Table 2
5 Bank
6 Construction
7 Carfactory
Table 3
1 5
1 6
1 7
2 5
2 6
2 7
3 5
3 6
3 7
I can make it so that the rows from table 1 are taken from 1 to 3 but not as to the row 1 all rows are taken from the table 2. Can anyone help me ? 我可以做到这样,以便表1中的行从1到3被取走,而不是第一行中所有行都从表2取走。有人可以帮我吗?
您可以使用CROSS JOIN实现预期的输出。
SELECT table1.id,table2.id FROM table1 CROSS JOIN table2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.