怎样用sql语句在一个表中搜索出某个字段没有重复的记录.

解决方案 »

  1.   

    select distinct fieldname form tablename
      

  2.   

    select * from table a where (select count(*) from table where a1=a.a1)=1
      

  3.   

    SELECT id,COUNT(*)AS count FROM user GROUP BY id HAVING  count>1;如果能搜索到就说明该字段重复为了使一个字段不存在重复值,
    可以为该字段设置 主键 或 UNIQUE
      

  4.   

    select distinct fieldname form tablename
      

  5.   

    to : idlient
    select distinct fieldname form tablename 可以,但是这样怎么显示所有记录?to : shuixin13
    UNIQUE 怎么用?
      

  6.   

    to : idlient
    写错了,不好意思.
    select distinct fieldname form tablename 可以,但是这样怎么显示所有字段?
      

  7.   

    select distinct * from yourtable
      

  8.   

    select distinct fieldname form tablename
      

  9.   

    SELECT id,COUNT(*)AS count FROM user GROUP BY id HAVING  count>1;
    决定的经典 程序员去年的11 12 期 杂志上有篇文章。
      

  10.   

    SELECT id,COUNT(*)AS count FROM user GROUP BY id HAVING  count>1;
      

  11.   

    select * distinct fieldname form tablename
      

  12.   

    distinct是把重复的字段只显示一个,还是用having对
      

  13.   

    select  distinct * form tablename
      

  14.   

    还是解决不了.请说更详细点.谢谢.
    select distinct Mobile from user where not isNull(ServiceID)
    我想把 Mobile字段中有重复的记录只取一个.
      

  15.   

    select Top 1 Mobile from user where not isNull(ServiceID)
      

  16.   

    下面的语句能查出重复的记录
    select mobile from user where mobile in(select mobile from user)
      

  17.   

    如果有a,b,c,d四个字段想查重复记录怎么查啊
    select  distinct(a,b,c,d) form tablename
    怎么写?
    ---------------------
    对不起了guolinchao (荒地校园) 借帖子一用。
      

  18.   

    这种问题多想想就行了。再不行就找一些SQL方面的书看啊。
      

  19.   

    解决了:
    id in (select max(id) from User group by Mobile )