select id,min(name) name from table1 group by id;

解决方案 »

  1.   

    要排序也是这样:
    select id,min(name)
    from table1
    group by id
    order by id
    赤赤 赤赤.
      

  2.   

    楼上几位写的和楼主给定的条件不一直啊,是楼主写错了???前面的是min(name),但是最后一个数据并不是给定的名字最小啊
      

  3.   

    select a.id,a.name from table1 a where a.rowid=(select min(b.rowid) from 
    table2 b where a.id=b.id)
      

  4.   

    select * from table1 a
    where rowid=(select min(rowid) from table1 where id=a.id)
      

  5.   

    select a.id , frist_value( a.name ) from table1 a group by a.id
      

  6.   

    min函数不是单行函数,不能用where.
    select a.id ,  a.name  from table1 a
     group by a.id
    having a.rowid=1
      

  7.   

    select distinct id,min(name) from table1 group by id order by id;
      

  8.   

    首先,我建立的表跟斑竹的表几乎是一样的,方法也是一样的。
    SQL> select *
      2  from tbtry
      3  /        ID NAME
    ---------- ----------
             1 a
             1 b
             2 c
             2 d
             3 a
             4 s
             5 y
             5 f
    方法一
       SQL>  select a.id,a.name
      2          from tbtry a,(select min(rowid) minrowid
      3                        from tbtry
      4                       group by id) b
      5          where a.rowid in b.minrowid
      6         /        ID NAME
    ---------- ----------
             1 a
             2 c
             3 a
             4 s
             5 y
    方法二
         SQL>  select id,name
      2           from tbtry
      3          where rowid in (select min(rowid)
      4                             from tbtry
      5                             group by id)
      6   /        ID NAME
    ---------- ----------
             1 a
             2 c
             3 a
             4 s
             5 y