有一个表,很多字段,我想选出某一个字段(A)没有重复的记录,请问SQL如何写?

解决方案 »

  1.   

    select distinct A from Table_name
      

  2.   

    给你一条语句作参考:
    select * from table_name where id in (select min(id) from table_name group by A)
      

  3.   

    不明白kasoo() 的意思,这样只能选一条出来啊
      

  4.   

    SELECT *
      FROM tabname JOIN (SELECT   a
                             FROM tabname
                         GROUP BY a
                           HAVING COUNT (1) = 1) ttab ON tabname.a = ttab.a
      

  5.   

    select * from tab where A in
    (select A from tab group by A having count(*)=1)
      

  6.   

    或者select * from tab t1 where not exists
    (select * from tab t2 where t1.A=t2.A and t1.tab_id!=t2.tab_id)其中tab_id是表tab的主键或不会重复的记录
      

  7.   

    select *
    from tbname tb
    where not exists(
         select 0 from(
            select *
        from (select t.*
         ,row_number()over(partition by A order by A) rn
      from tbname t) where rn>1) 
       where A=tb.A
    )
    比较麻烦,应该有更好的方法
      

  8.   

    select schoolname from (select schoolname,rownum as num from t_school)  where num<100;