比如有表
a   b   c
a1  b1  c1
a1  b3  c5
a2  b3  c5
a3  b5  c8我想得出下面的结果:
a   b   c
a1  b1  c1
a2  b3  c5
a3  b5  c8就是有的记录重复,我想选出重复的记录的第一条,不重复的就直接选出来
谢谢了

解决方案 »

  1.   

    有字段表明先后比如id
    select min(id) as n,a,b,c from table group by a,b,c
      

  2.   

    select id=identity(int,1,1),a,b,c  into #t from table1 
    select a,b,c from #t  g 
    where not exists(select * from #t where a=g.a and id<g.id)
      

  3.   

    DECLARE @T TABLE(A VARCHAR(2),B VARCHAR(2),C VARCHAR(2))INSERT INTO @T 
    SELECT 'a1',  'b1',  'c1' UNION ALL
    SELECT 'a1',  'b3',  'c5' UNION ALL
    SELECT 'a2',  'b3',  'c5' UNION ALL
    SELECT 'a3',  'b5',  'c8' SELECT A , MIN(B ) AS B,MIN( C) AS C
    FROM @T 
    GROUP BY A
      

  4.   

    create table A
    (
     a varchar(5),
     b varchar(5),
     c varchar(5)
    )insert A select 'a1','b1','c1'
    insert A select 'a1','b3','c5'
    insert A select 'a2','b3','c5'
    insert A select 'a3','b5','c8'select a, min(B) as b,min(c) as c from A group by A