delete from table 
where id in (
             select id from (
                              select id,count(id) as dup_count     from  talbe group by id) 
                              where dup_count>1
                             )

解决方案 »

  1.   

    delete from tmp
    where id in (
                 select id from (
                                  select id,count(id) as dup_count     from  tmp group by id) a
                                  where a.dup_count>1
                                 )
      

  2.   

    delete table1
    from table1 a,
    (select id from table1 group by id having count(id)>1) b
    where a.id=b.id
      

  3.   

    select distinct * into #tmp from yourtable 
    truncate table yourtable
    insert yourtable select * from #tmp
      

  4.   

    chumpg和lmcglmc你们把所有相同记录都delete了,sky_blue做法是保留了一项
      

  5.   

    delete from table
    where id not in (select id from table)
      

  6.   

    修正:
    delete from table
    where id not in (select max(id) from table group by id)
      

  7.   

    参阅《程序员》杂志 2002年11月: 《一道褒贬不一的 SQL 考试题》一文,大概是第一题: