所以说我想...
插入tableA,tableB中的2个变量,但只有tableB中具有1个变量等于某个事物的行...
嗯,让我们看看我是否可以更具体...
我想在tableA中为tableB中courseid为11的每一行的userid和courseid创建一个新行
请指教
INSERT
INTO tableA (col1, col2)
SELECT userid, courseid
FROM tableB
WHERE courseid = 11
好吧,不知道您在 tableA 中有哪些列,我会说:
insert into tableA
select
userid,
courseid
from tableB where
courseid=11
INSERT INTO TableA (userid, courseid)
SELECT userid, courseid FROM TableB
WHERE courseid = 11
那应该为你做。
你没有提到你正在使用哪个数据库。
对我来说,MS Access 在尝试做这样的事情时被证明是非常错误的。
如果要使用现有数据创建新表,则可以使用SELECT INTO :
SELECT <columns here> INTO tableA FROM tableB WHERE <restrictions here>
如果要将现有数据插入现有表中,则必须使用:
INSERT INTO tableA (<destination columns>) SELECT <source columns> FROM tableB WHERE <restrictions here>
如其他答案中所述
插入 tableA(column1,column2,column3) 从表 B 中选择 column1,column2,column3