读书人

一个表中的数据安插到另一个表

发布时间: 2012-12-30 10:43:15 作者: rapoo

一个表中的数据插入到另一个表
如何将B表中的数据插入到B表中

注意:如果imei字段重复,则不插入

意思是说只插入不重复的数据。
[解决办法]
B表数据插入A表中(设表结构相同,如不相同,则选择列进行操作):
insert into A
select * from B t where not exists(select 1 from A where imei=t.imei)
[解决办法]
Insert into tb(字段)
Select 字段 From b
Where Not exists(select 1 from tb Where imei=b.imei)
[解决办法]
因为在exsits/not exists里面要做表关联,你放出来,那里面就不知道成什么样了。
[解决办法]
在not exists/exists外面的那些where条件,只对not exists/exists外面的那个/些表有效
[解决办法]



insert into A(字段)
select 字段
from B left join A on A.imei = B.imei
where A.imei is null

读书人网 >SQL Server

热点推荐