create table a(id int,name varchar(100))
insert into a select 1,'a'
insert into a select 2,'b'
insert into a select 3,'c'create table b(id int,name varchar(100))insert into b select * from (
select * from a where name='a' or name ='b'
and not exists(select 1 from b where id=a.id)
)ainsert into b select * from (
select * from a where name='a' or name ='b'
and not exists(select 1 from b where id=a.id)
)a不看答案,结果是什么?
insert into a select 1,'a'
insert into a select 2,'b'
insert into a select 3,'c'create table b(id int,name varchar(100))insert into b select * from (
select * from a where name='a' or name ='b'
and not exists(select 1 from b where id=a.id)
)ainsert into b select * from (
select * from a where name='a' or name ='b'
and not exists(select 1 from b where id=a.id)
)a不看答案,结果是什么?
----------- ----------------------------------------------------------------------------------------------------
1 a
2 b
1 a(所影响的行数为 3 行)id name
----------- ----------------------------------------------------------------------------------------------------
1 a
2 b
3 c(所影响的行数为 3 行)
----------- ----------------------------------------------------------------------------------------------------
1 a
2 b
1 a刚才试了一下
id,name
1,a
2,bid,name
1,a
2,b-_-|||
1结果id name
1 a
2 b2结果id name
1 a
2 b
1 a
刚刚因为这个就多导了200多万记录 !呵呵 大家注意拉
id name
1 a
2 b
3 ctable b
id name
1 a
2 b
1 a
insert into b select * from (
select * from a where (name='a' or name ='b')
and not exists(select 1 from b where id=a.id)
)a
---
按你的本意少了一个括号吧
and not exists(select 1 from b where id=a.id)
不打括号当然 糊弄大家呗?
insert into b select * from (
select * from a where name='a' or name ='b'
and not exists(select 1 from b where id=a.id)
)a
--相当于
insert into b select * from (
select * from a
where name='a' or (name ='b' and not exists(select 1 from b where id=a.id))
)a
insert into b select * from (
select * from a where name='a' or name ='b'
and not exists(select 1 from b where id=a.id)
)a
--相当于
insert into b select * from (
select * from a
where name='a' or (name ='b' and not exists(select 1 from b where id=a.id))
)a