表A
id userid
1     2
2     2
3     5我想根据userid删掉id为1和2的记录,下面这么写为什么错了,说子查询返回的值不止一个delete from A where id in (select id from A where userid=2)

解决方案 »

  1.   

    delete a where id in(1,2)
      

  2.   

    Trydelete a from A a,A b where a.id=b.id and b.userid=2
      

  3.   

    create table #表A (id int,userid int)
    GO
    insert into #表A
    select 1,    2 union all
    select 2,    2 union all
    select 3,    5 delete from #表A where id in (select id from #表A where userid=2)
    (2 行受影响)select * from #表A
    /*
    id userid
    3 5
    */