某表Table1有一字段F2有重复记录,我想得到F2没有重复的记录(有重复的记录一条也不要)。自己倒是写了一个语句:Select G.* From (Select A.F2, Count(A.F1) From Table1 As A Group By A.F2 Having (Count(*) = 1)) As G这个语句效率太低,对于大数据量足足用了5分钟。请教更有效的语句。谢谢!

解决方案 »

  1.   


    select * from Table1 where F2 not exists(select F2 from Table1 group by F2 having count(F2)>1)
      

  2.   

    --起别名,
    select * from Table1 where F2 not exists(select F2 from Table1 a where table1.f2=a.f2 group by F2 having count(F2)>1)
      

  3.   

    相对于exists  觉得inner join 效率应该会高一点
      

  4.   

    --删除所有重复的name行,一行也不留 delete [user] from [user] t   
    inner  join   
    (select   id   from   [user]   a   where   exists(select   1   from   [user]  
    where   name = a.name   group   by   name   having   count(*)   >   1))   as b 
    on t.id = b.id