我相信这很简单,只是我无法得到正确的搜索词以找到答案。 但我有一个包含ID的位置表。
ID| Name
1 | Foo
2 | Bar
3 | Blah
还有一张表(table2),其中有一个字段引用了那些位置ID:
ID| LocationID | Foo | Bar
1 | 1 | ... | ...
2 | 2 | ..
3 | 5 | ...
当 LocationId = location 中的一个值时,我想要做的是对另一张表中的每个 ID 添加一条记录。例如:
"insert into table2 (locationID, foo, bar) values (1, "hello", "world");"
"insert into table2 (locationID, foo, bar) values (2, "hello", "world");"
SELECT ID, 'hello', 'world'
可能看起来有点奇怪,但它选择了列ID
和纯文本值 'hello' 和 'world'。您可以通过执行SELECT ID, 'hello', 'world' FROM table1
(即没有INSERT INTO
部分)来自行查看将要插入的内容。 - Peter van der Wal