如题:
在A表中
col1  col2  col3  col4   col5  col6  col7   col8   col9 列
1      a     c     d       e     f    g      h      j
2      b     r     u       u     i    o      p      p
3      q     w     d       f     e    t      t      y 
4      w     y     u       i     o    y      u      p
5      l     k     j       h     g    b      m      n这样一个表,将整个表的col2  col3  col4   col5  col6  col7   col8   col9 导入到B表,B表中col2  col3  col4   col5  字段为唯一索引,不能重复问题,怎么将A表中col2  col3  col4   col5  重复的去掉,只留住一条,导入时不出错

解决方案 »

  1.   

    delete
     t 
    from
     a t 
    where
     exists(select 1 from a where col2=t.clo2 and col3=t.col3 and col4=t.col4 and col5=t.col5 and col1<>t.col1)
      

  2.   

     insert into b
    select col2 col3 col4 col5 col6 col7 col8 col9 from ta  a
    where not exists ( select 1 from ta where col2=a.col2 and id>a.id)
    and not exists ( select 1 from ta where col2=a.col2 and id>a.id)
    and not exists ( select 1 from ta where col3=a.col3 and id>a.id)
    and not exists ( select 1 from ta where col4=a.col4 and id>a.id)
    and not exists ( select 1 from ta where col5=a.col5 and id>a.id)
      

  3.   

    请清楚点呢
    delete
     t 
    from
     a t??
      

  4.   

    本帖最后由 roy_88 于 2010-03-24 10:03:09 编辑
      

  5.   

    LZ说的有问题,如果col2 col3 col4 col5相同,后面的列不同要怎么导入,取那条??????
      

  6.   

    哎,试了几个方法都不行呢。说的更明确些,
    col1 col2 col3 col4 col5 col6 col7 col8 col9 列
    9个列,导到B表的时候要确保col4  手机号码这一列唯一的,不能有重复