复制代码 代码如下:
create table insertTest(id int(4),name varchar(12));
insert into insertTest values(100,‘liudehua');
insert into insertTest values(101,‘zhourunfa');
insert into insertTest values(102,‘zhouhuajian');
复制代码 代码如下:
insert into insertTest select * from insertTest2;
复制代码 代码如下:
INSERT INTO 目标表 (字段1, 字段2, …) SELECT 字段1, 字段2, … FROM 来源表;
复制代码 代码如下:
insert into insertTest2(id) select id from insertTest2;
复制代码 代码如下:
INSERT INTO 目标表
(字段1, 字段2, …)
SELECT 字段1, 字段2, …
FROM 来源表
WHERE not exists (select * from 目标表
where 目标表.比较字段 = 来源表.比较字段);
复制代码 代码如下:
insert into insertTest2
(id,name)
select id,name
from insertTest
where not exists (select * from insertTest2
where insertTest2.id=insertTest.id);
复制代码 代码如下:
insert into insertTest
(id, name)
SELECT 100, ‘liudehua'
FROM dual
WHERE not exists (select * from insertTest
where insertTest.id = 100);
新闻热点
疑难解答