id      city_id y_id    nam                    icon   
44198 1391 131 loong 9
44198 1391 131 loong 14上述表数据,想要根据id去除重复记录,最终结果
44198 1391 131 loong 9
或者
44198 1391 131 loong 14都可以。
请各位大侠帮忙。

解决方案 »

  1.   

    你说的通过select 查询么,暂且认为表是customer
    select * from customer where id in  (select distinct(id) from customer);
      

  2.   

    select distinct(id) from customer获取id为44198 select * from customer where id in ('44198')结果还是两条呀。
      

  3.   

    delete from table_name where (id,rowid) not in(select id,max(rowid) from table_name group by id)
      

  4.   


    with t1 as
    (
         select 44198 id,1391 city_id,131 y_id,'loong' nam,9 icon from dual
         union all
         select 44198 id,1391 city_id,131 y_id,'loong' nam,14 icon from dual
         union all
         select 44444 id,1111 city_id,222 y_id,'loong' nam,4 icon from dual
         union all
         select 44444 id,1111 city_id,222 y_id,'loong' nam,1 icon from dual
    )select id,city_id,y_id,nam,icon
    from 
    (
           select t1.*,row_number() over(partition by id order by rownum) rn
           from t1
    )
    where rn = 1
         id    city_id   y_id   nam   icon
    --------------------------------------------------
    1 44198 1391 131 loong 9
    2 44444 1111 222 loong 4
      

  5.   

    既然你随便去哪一个就行,那么可以这样好了
    select distinct  id,city_id,y_id nam,(max)icon from 表 group by id
      

  6.   

    select *
      from table_name a
     where not exists (select 1
              from table_name 
             where dae100 = a.dae100
              and rowid>a.rowid);
      

  7.   

    select * from customer where id rowid (select max(rowid) from customer group by id );不好意思上次的写错了,这次补上,利用物理地址。
      

  8.   

    select * from customer where rowid (select max(rowid) from customer group by id );
      

  9.   

    select * from customer where rowid in (select max(rowid) from customer group by id );
      

  10.   

    删除重复记录语句,重复记录只保留一条,其他的都删除,这是最高效的:delete from table a where a.rowid!=(select max(rowid) from table  b where a.id=b.id an a.city_id=b.city_id and a.nam=b.nam);
      

  11.   

    如果只需要根据id判断重不重复,只需要条件a.id=b.id,其他条件不需要。
      

  12.   

    --删除重复记录
    delete  from  tablename a  where  a.rowid > (select min(b.rowid) 
    from  tablename b  where  a.id=b.id an a.city_id=b.city_id and a.y_id=b.y_id and a.nam=b.nam);
      

  13.   

    楼上的,,请不要误人子弟。。查询不存在重复数据
    select * from table1 where table1_id not in (select max (table1_id) from table2 group by table2_id having count(*)>1)
      

  14.   

    参看http://topic.csdn.net/u/20071224/10/b20e2cf3-85e1-4f2e-b368-afbc28e15cc2.html
      

  15.   

    delete from T a where a.rowid > (select min(b.rowid)  
    from T b where a.id=b.id and a.city_id=b.city_id and a.y_id=b.y_id and a.nam=b.nam);
      

  16.   

    假设你的表是emp表,依据部门号去重,可以这样做,依据rowid
    SELECT *
      FROM EMP T
     WHERE (T.EMPNO, ROWID) IN
           (SELECT T.EMPNO, MAX(ROWID) FROM EMP T GROUP BY T.EMPNO)
      

  17.   

    可以分三步:
    1.首选创建一个临时表
    create table temp as select * from user group by id ;
    2.删除原表user
    drop table user;
    3.在将临时表重命名
    alter table temp rename user;个人觉得针对表中数据少时。
      

  18.   

    delete from cs_ls
     where rowid not in
           (select max(rowid) from cs_ls a group by a.id);
    /*按id排序,取rowid最大值,将not in 最大值的记录删除*/rowid是一个伪列,是用来确保表中行的唯一性.