Select 
*
From
Table11111 A
Where ID In (Select Min(ID) From Table11111 Group By name )

解决方案 »

  1.   

    select t.* from Table11111 t where not exists(select 1 form Table11111 where name=t.name and ID<t.ID)
      

  2.   

    select * from Table11111 t where t.ID=(select min(ID) from Table11111 where name=t.name)
      

  3.   

    或者Select 
    *
    From
    Table11111 A
    Where ID = (Select Min(ID) From Table11111 Where name = A.name)
      

  4.   

    select min(id) as id,
    name,
    type,
    min(re)
    from table11111
    group by name,type
      

  5.   

    if object_id('pubs..tb') is not null
       drop table tb
    gocreate table tb(ID int,name varchar(10),type int,re varchar(10))
    insert into tb(ID,name,type,re) values(3 ,   'BB',      2,        'qq3')
    insert into tb(ID,name,type,re) values(11,   'AA',      2,        'qq1')
    insert into tb(ID,name,type,re) values(14,   'BB',      2,        'qq4')
    insert into tb(ID,name,type,re) values(21,   'AA',      2 ,       'qq2')select a.* from tb a,
    (select name , min(id) id from tb group by name) b
    where a.name = b.name and a.id = b.iddrop table tb
    /*
    ID          name       type        re     
    ----------- ---------- ----------- ---------- 
    11          AA         2           qq1
    3           BB         2           qq3(所影响的行数为 2 行)
    */
      

  6.   

    Create Table Table11111
    (ID Int,
     name Varchar(10),
     type Int,
     re Varchar(100))
    Insert Table11111 Select 3,     'BB',      2,        'qq3'
    Union All Select 11,   'AA',      2,        'qq1'
    Union All Select 14,   'BB',      2,        'qq4'
    Union All Select 21,   'AA',      2,        'qq2'
    GO
    --方法一:
    Select 
    *
    From
    Table11111 A
    Where ID In (Select Min(ID) From Table11111 Group By name )--方法二:
    Select 
    *
    From
    Table11111 A
    Where ID = (Select Min(ID) From Table11111 Where name = A.name)--方法三:
    Select 
    *
    From Table11111 A
    Where Not Exists(Select ID From Table11111 Where name = A.name And ID < A.ID)
    --方法四:Select 
    A.*
    From
    Table11111 A
    Inner Join
    (Select MIn(ID) As ID, name From Table11111 Group By name) B
    On A.ID = B.ID And A.name = B.name
    GO
    Drop Table Table11111
    --Result
    /*
    ID name type re
    3 BB 2 qq3
    11 AA 2 qq1
    */