select index,name,age from table
where index in
(
select index
from
(
select name,age,min(index) as index from table
group by name,age))

解决方案 »

  1.   

    如果想删除的话,可以
    delete from table
    where index not in
    (
    select index
    from
    (
    select name,age,min(index) as index from table
    group by name,age))
      

  2.   

    SQL> select * from tmp;ID
    --------------------------------------------------
    NAME
    --------------------------------------------------
    1
    lhg31
    lhg22
    lhg2
    ID
    --------------------------------------------------
    NAME
    --------------------------------------------------
    1
    lhg
    SQL> delete  from ( select * from tmp where tmp.rowid != (
      2         select max(rowid) from tmp t where t.id= tmp.id)) Tp;已删除2行。SQL> select * from tmp;ID
    --------------------------------------------------
    NAME
    --------------------------------------------------
    2
    lhg21
    lhg
    name --> id
      

  3.   

    select index, name, age from(
         select index, name, age, 
                dense_rank() over(
                     partition by name
                     order by index) dr
              from table)
        where dr = 1
             order by index;
    BTW: The Oracle's version is must 8i or higher!Hope this will help you.
      

  4.   

    delete from table where rowid not (select max(rowid) from table group by name having count(*) > 1)
      

  5.   

    delete from yourTable a
    where a.rowid < select max(rowid) from yourTable b where a.index=b.index);