INSERT INTO TABLE_2
(id, name)
SELECT t1.id,
t1.name
FROM TABLE_1 t1
WHERE NOT EXISTS(SELECT id
FROM TABLE_2 t2
WHERE t2.id = t1.id)
使用NOT IN:
INSERT INTO TABLE_2
(id, name)
SELECT t1.id,
t1.name
FROM TABLE_1 t1
WHERE t1.id NOT IN (SELECT id
FROM TABLE_2)
使用LEFT JOIN/IS NULL:
INSERT INTO TABLE_2
(id, name)
SELECT t1.id,
t1.name
FROM TABLE_1 t1
LEFT JOIN TABLE_2 t2 ON t2.id = t1.id
WHERE t2.id IS NULL
insert into 表(列名一,列明二)select 01,20130910 union
select 02,20130911 union
select 03,20130912 union
select 04,20130913 union
select 05,20130914 union
select 06,20130915
这样可以添加多条数据 ,union在最后一条数据里不用加上。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)