select a.user_name, a.mc_uid, b.user_name, b.mc_uid
  from user_info a, user_info b
 where a.mc_uid = b.mc_uid
   and a.user_name <> b.user_name这样查出来的有两条数据其实是一样的  求用什么办法能除去其中一条记录

解决方案 »

  1.   

    distinct 不行  这个sql的意思是先将表自连  然后找出用户名不同的选项  很明显有两条记录  如下例
         a                        b                  a                  b
      4545  21467980-fb89-4aa4-8259-50d25ba65090 huhao 21467980-fb89-4aa4-8259-50d25ba65090
      huhao  21467980-fb89-4aa4-8259-50d25ba65090 4545 21467980-fb89-4aa4-8259-50d25ba65090
      

  2.   

    有就是说 我只要一行
    4545 21467980-fb89-4aa4-8259-50d25ba65090 huhao 21467980-fb89-4aa4-8259-50d25ba65090 或者
    huhao 21467980-fb89-4aa4-8259-50d25ba65090 4545 21467980-fb89-4aa4-8259-50d25ba65090 求解啊
      

  3.   


    --是不是想要取mc_uid相同的只取一条?如果是,下面这个应该可以
    select *
    from user_info a where a.rowid = (select max(b.rowid) from user_info b where b.mc_uid=a.mc_uid)
      

  4.   


    with t as(
    select 'a' str,1 num from dual
    union all
    select 'b',1 from dual
    union all
    select 'c',2 from dual
    )
    select distinct greatest(t1.str, t2.str),
                    t1.num,
                    least(t1.str, t2.str),
                    t2.num
      from t t1, t t2
     where t1.num = t2.num
       and t1.str <> t2.strGREATEST(T1.STR,T2.STR)        NUM LEAST(T1.STR,T2.STR)        NUM
    ----------------------- ---------- -------------------- ----------
    b                                1 a                             1