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不看答案,结果是什么?

解决方案 »

  1.   

    id          name                                                                                                 
    ----------- ---------------------------------------------------------------------------------------------------- 
    1           a
    2           b
    1           a(所影响的行数为 3 行)id          name                                                                                                 
    ----------- ---------------------------------------------------------------------------------------------------- 
    1           a
    2           b
    3           c(所影响的行数为 3 行)
      

  2.   

    id          name                                                                                                 
    ----------- ---------------------------------------------------------------------------------------------------- 
    1           a
    2           b
    1           a刚才试了一下
      

  3.   

    以为是(逻辑上好像也应该是):
    id,name
    1,a
    2,bid,name
    1,a
    2,b-_-|||
      

  4.   


    1结果id name
    1 a
    2 b2结果id name
    1 a
    2 b
    1 a
    刚刚因为这个就多导了200多万记录 !呵呵 大家注意拉
      

  5.   

    table a
    id      name
    1 a
    2 b
    3 ctable b
    id      name
    1 a
    2 b
    1 a
      

  6.   

    select * from b
    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
    ---
    按你的本意少了一个括号吧
      

  7.   

    切  不打括号where (name='a' or name ='b')
    and not exists(select 1 from b where id=a.id)
    不打括号当然  糊弄大家呗?
      

  8.   

    --这个是因为or的优先级比and低,
    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
      

  9.   

    --这个是因为or的优先级比and低,
    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