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

SQL中同一数据库不同表之间的的数据导入问题?
我现在要将表1(Mobile)字段MobileNo的数据导入到表2(MobilePhone)字段Mobile中,如果表2中存在的记录则不导入。这个语句应该怎么写啊?

------解决方案--------------------

Insert MobilePhone (Mobile)
Select MobileNo From Mobile
Where Not Exists(Select Mobile From MobilePhone Where Mobile = Mobile.MobileNo)
------解决方案--------------------
insert into 表2(mobile) select mobile from 表1 where mobile not in(select mobile from 表2)
------解决方案--------------------
Insert MobilePhone (Mobile)
Select MobileNo From Mobile
Where MobileNo Not In (Select Mobile From MobilePhone)
------解决方案--------------------

Insert MobilePhone (Mobile)
Select A.MobileNo From Mobile A
Left Join MobilePhone B
On A.MobileNo = B.Mobile
Where B.Mobile Is Null
------解决方案--------------------
--如果是要插入
--方法一:
Insert MobilePhone (Mobile)
Select MobileNo From Mobile
Where Not Exists(Select Mobile From MobilePhone Where Mobile = Mobile.MobileNo)
--方法二:
Insert MobilePhone (Mobile)
Select MobileNo From Mobile
Where MobileNo Not In (Select Mobile From MobilePhone)
--方法三:
Insert MobilePhone (Mobile)
Select A.MobileNo From Mobile A
Left Join MobilePhone B
On A.MobileNo = B.Mobile
Where B.Mobile Is Null
------解决方案--------------------
Insert MobilePhone(Mobile) Select MobileNo From Mobile Where MobileNo not in (Select Mobile From MobilePhone)