SQL语句 如何将已知数据和查询一个表中的数据一起插入另一个表

例如将字符串“张三”和在另一张表table1查询得到的数据一起插入到另一张表中

第1个回答  2021-05-27

例子:把table2中李四的city和其他数据一起插入table1

insert into table1(id, name, age, sex, city) select '1001', '张三', '18', '男', t.city from table2 t where t.name='李四';

table1和table2的表结构不需要相同。

第2个回答  2011-04-18
INSERT INTO 表2(字段名1,字段名2 )
SELECT 字段名1, "张三"
FROM 表1;

Access中通过
第3个回答  2011-04-17
insert into table2 values ('张三',select 字段 from table)追问

貌似不对啊

第4个回答  2011-04-17
insert into table2(field)
(select '张三' union all select field from table1)追问

不对啊

追答

是要把‘张三’与table1中的数据写到一个字段中吗?还是不同的字段?给一个table1和另一个表的表结构吧。

如果写在一个字段中:
insert into table2(field)
select '张三' union all select field from table1

本回答被提问者采纳
相似回答