我敢肯定,这很简单,我只是无法获得正确的搜索词来找到答案。但是我有一张桌子,上面有ID的位置
ID| Name
1 | Foo
2 | Bar
3 | Blah
另一个表(table2)具有引用这些位置ID的字段:
ID| LocationID | Foo | Bar
1 | 1 | ... | ...
2 | 2 | ..
3 | 5 | ...
其中LocationId =来自位置的值。我想做的是为位置(1、2、3 ...)中的每个ID添加一条记录到另一个表。因此,例如:
"insert into table2 (locationID, foo, bar) values (1, "hello", "world");"
"insert into table2 (locationID, foo, bar) values (2, "hello", "world");"
等等..
您可以使用INSERT INTO ... SELECT,因此对于您的示例
INSERT INTO table2 (locationID, foo, bar) SELECT ID, 'hello', 'world' FROM table1
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句