INSERT INTO table2 (firstname, lastname, middlename) SELECT firstname, lastname FROM table1 WHERE id = 1
如何为table2'middlename'列插入数据?在我的table1中,只有两列'firstname'和'lastname'
答案 0 :(得分:0)
从列表中删除middlename
列:
INSERT INTO table2 (firstname,lastname)
SELECT firstname, lastname FROM table1 WHERE id = 1
答案 1 :(得分:0)
尝试此查询
INSERT INTO table2 (firstname, lastname, middlename) SELECT firstname, lastname, "NA" FROM table1 WHERE id = 1
答案 2 :(得分:0)
INSERT INTO table2 (firstname,lastname) SELECT firstname, lastname FROM table1
将table2中的中间名留空,因为你没有
的记录答案 3 :(得分:0)
如果它是必填列(即NOT NULL且未定义默认值),则必须选择常量。 像
这样的东西insert into table2 (firstname, lastname, middlename)
select firstname, lastname, 'N/A' from table1 where id = 1;
如果列是可选的,请忽略列列表中的列。像
insert into table2 (firstname, lastname)
select firstname, lastname from table1 where id = 1;