大神们.我又来问问题来了
查询表A插入表B
INSERT INTO A ( AID1,AID2) SELECT BID1,BID2 FROM B
不能插入重复的,AID1可以重复,AID2也可以,但是加起来不能重复.....如何判断切能保持效率
[解决办法]
建议用left join来判断把:
create table A表(ID1 varchar(20), ID2 int)
insert into A表
select 'a', 1 union all
select 'a', 2 union all
select 'b', 1 union all
select 'b', 3
create table B表(ID1 varchar(20), ID2 int)
insert into B表
select 'a', 3 union all
select 'a', 1 union all
select 'b', 2 union all
select 'b', 3
go
insert into A表
select b.*
from B表 b
left join A表 a
on a.ID1 = b.ID1 and a.ID2 = b.ID2
where a.ID1 is null
go