日期:2014-05-18  浏览次数:20547 次

怎么将查询出来的很多条记录插入到另一个表中去??
我有两个表分别是表1和表2,表2里面装的是已经提取的记录,每一次取记录的时候要有一个筛选,就是说选的记录不在表2里面。提取表1里面的记录再存到表2里面,表示已经提取过了。请问有什么sql可以达到这样的效果
我有这样一句     insert   into   表2   values(select   *   from   表1   where   关键字段   not   in   (select   关键字段   from   表2))

------解决方案--------------------
insert into 表2
select * from 表1 where 关键字段 not in (select 关键字段 from 表2)

------解决方案--------------------
insert into 表2
select * from 表1 where 关键字段 not in (select 关键字段 from 表2)
------解决方案--------------------
insert into 表2
select distinct * from 表1 where not exists(select 1 from 表2 where 表1.关键字段=表2.关键字段)

------解决方案--------------------
insert into 表2
select * from 表1 where 关键字段 not in (select 关键字段 from 表2)

--or
insert into 表2
select * from 表1 where not exists(select 1 from 表2 where 表1.关键字段=表2.关键字段)


我要取的是前5000个不重复的 distinct top 5000 关键字段 应该是这样的吧?
-------------------------
对。。是这样。。