字段1     字段2   字段3     字段4    字段5
5445 b11112 asfd fdsfdsaf asdf
23 1111333 sfda fsad af
234 111a14 dafds afsda NULL
2 x11122 sdsaf fdsa dfas
22 11123 fa aa dsafds
123 m111v24 fdaf sfs fdsafsd
123 xxxf fd sdds fdsaddsdfsd
我要得到的结果:
字段1     字段2   字段3     字段4    字段5
5445 b11112 asfd fdsfdsaf asdf
23 1111333 sfda fsad af
234 111a14 dafds afsda NULL
2 x11122 sdsaf fdsa dfas
22 11123 fa aa dsafds
123 m111v24 fdaf sfs fdsafsd
也就是说只要字段1重复的随便取出一个就行.我是这样写的SQL语句:
select 字段1 ,字段2,字段3,字段4,字段5 from [table] where 字段1 in (select 字段1 from [table] group by a having count(a)>=1)

解决方案 »

  1.   

    select * from table where id  in(select DISTINCT id  from table)
      

  2.   

    如果该表有Unique的字段ID的话,2楼是正确的。否则可能只能用存储过程了!
      

  3.   

    select Min(字段2) from  [table] group by 字段1给分!
      

  4.   

    嗯,下面这样应该可行
    select Table2.*
    From
    (select 字段1,min(字段2)  as 字段2 from [table] group by 字段1) Table1
    inner join  [table] Table2 
    on Table1.字段1=Table2.字段1 and Table1.字段2=Table2.字段2