我想delete表a中,不包括表b,表c,表d的数据,  
表a,b,c,d中都有列item是相同的,
这个语句怎么写

解决方案 »

  1.   

    delete a
    from a
    where item not in( select item from b union
                      select item from c union 
                      select item from d)
      

  2.   

    create table a(item int)create table b(item int)create table c(item int)create table d(item int)
    insert a select 1
    insert a select 2
    insert a select 3
    insert a select 4
    insert a select 5
    insert b select 1
    insert c select 2
    insert d select 3
    go
    ---1
    delete a
    where not exists( select 1 from ( select item from b union
                      select item from c union 
                      select item from d ) e
                               where a.item = e.item)
    ---2
    delete a
    from a
    where item not in( select item from b union
                      select item from c union 
                      select item from d)
    select * from adrop table a,b,c,d/*
    item        
    ----------- 
    1
    2
    3(所影响的行数为 3 行)
    */