我正在尝试使用称为table1_table2的查找表在table1中的max(id)与table2中的所有id之间创建多对多关系。
最终,使table1_table2中的行为:
table1_id, table2_id 30, 1 30, 2 30, 3 ... 30, 10000
我怎样才能做到这一点?
我试过了
insert into insert into table1_table2 (table1_id, table2_id) values (select max(id) from table2, select id from table3);
和
insert into insert into table1_table2 (table1_id, table2_id) select max(table1_id), table2_id from table1 join table1_table2 on table1_table2.table1_id = table1.id outer join table1_table2 on table1_table2.table2_id = table2.id;
但似乎都不起作用
听起来这就是您想要的:
INSERT INTO table1_table2 (table1_id, table2_id) SELECT MAX(table1.id), table2.id FROM table1, table2 GROUP BY table2.id;