我想通过交叉连接两个表 Table_A 和 Table_B
将值插入到 Table_C
中。
Table_A contains two attributes ID and item.
Table_B contains two attributes ID and color.
Table_C contains four attributes ID,item,color,quantity.
所有 ID
都有 AUTO INCREMENT
。
假设每个项目都可以具有所有颜色
,我需要创建一个关于它的关系。
我应该如何为此编写查询?我如何引用交叉连接 item
和 color
的关系。
我的解决方案是创建一个连接这两个表的中间第三个表,然后使用该表将值插入 Table_C
。但我很确定对此有更好的优化解决方案。
提前致谢。
最佳答案
不需要临时表...你可以这样做:
insert into ...
select ... from ...
编写您需要“填充”您提到的临时表的查询,并将这些行直接插入到您的最终表中。
关于mysql - 通过 CROSS JOINing 两个表将值插入第三个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16914282/