提取不重复的数据,要怎么写如:表 aaaa  bb  cc   dd
a   s    s   d
a   d    d   d
a   e    r   r 
b   d    f   g
b   g    f   f就是有aa字段中有重复的,就值显示一个 效果:
aa  bb  cc   dd
a   s    s   d
b   d    f   g这样SQL语句要怎么写??
不要用到中间表的,就是不想用中间表看看有没有办法尽量最简单的语句,
知道的人教教我,XX

解决方案 »

  1.   

    select t.* from 表 t where not exists(select 1 from 表 where aa=t.aa and bb<t.bb)
      

  2.   

    表:a
    id name
    11 aaaa
    11 bbbb
    11 cccc
    22 dddd
    22 eeee
    22 ffff
     
    如何将表中的相同id号的第一条记录取出来?即:
    id name
    11 aaaa
    22 dddd
    CREATE TABLE #a (
           [id] [char] (10),
           [name] [char] (10) 
    )insert into #a(id,name) values('11','aaaa')  
    insert into #a(id,name) values('11','bbbb')  
    insert into #a(id,name) values('11','cccc')  
    insert into #a(id,name) values('22','dddd')  
    insert into #a(id,name) values('22','eeee')  
    insert into #a(id,name) values('22','ffff')  select * from #a b
    where name=(select top 1 name from #a where id=b.id)drop table #aid         name       
    ---------- ---------- 
    11         aaaa      
    22         dddd      (所影响的行数为 2 行)
    CREATE TABLE #a (
           [id] [char] (10),
           [name] [char] (10) 
    )insert into #a(id,name) values('11','aaaa')  
    insert into #a(id,name) values('11','bbbb')  
    insert into #a(id,name) values('11','cccc')  
    insert into #a(id,name) values('22','dddd')  
    insert into #a(id,name) values('22','eeee')  
    insert into #a(id,name) values('22','ffff')  select id1=identity(int,1,1),* into #t from #a
    go
    select id,name from #t where id1 in(select min(id1) from #t group by id)drop table #a
    drop table #tid         name       
    ---------- ---------- 
    11         aaaa      
    22         dddd      (所影响的行数为 2 行)
      

  3.   

    select * from tb t where bb=(select top 1 bb from #a where aa=t.aa)