select id ,email from user where email in 
(select b.email from user where trim(ifnull(b.email,'')) <>''group by b.email having count(*)>=2)
order by email-这样的语句是很多 的     。 有时候他跑几个小时不出数据。这种表达方式显然是错误的。  问错误原因 

修改可以下面的方式:
select id ,email from user inner join (select email from user where trim(ifnull(b.email,'')) <>''group by b.email having count(*)>=2) b
on a.email=b.email 
order by email
这个是可以的
)需要知道错误原因? (mysql不支持这种表达?)

解决方案 »

  1.   

    有没有更简洁的找出几个字段值组合重复的sql写法提供另外1个写法 (就是有点复杂)
    select id from rt t 
    where exists (select 1    from rt m    where     m.a=t.a
        and m.b=t.b
        and m.c=t.c
      

  2.   

    where 条件in表达式在一个不确的范围。
      

  3.   

    在第1个帖子里的执行时间是10sselect id from rt t 
    where exists (select 1    from rt m    where    m.a=t.a 
        and m.b=t.b 
        and m.c=t.c    这个时间太长 不知道等到什么时间去了
      

  4.   

    奇怪 这里死活 select id from rt t 
    where exists (select 1    from rt m    where    m.a=t.a 
        and m.b=t.b 
        and m.c=t.c不能出现数据  (昨天一个大表是可以出数据 这种写法 )
      

  5.   

    3004628化了一个小时才解决这个问题实际上2个sql执行结果都一直 的 有时候必须检验sql (mysql有时候对一种写法)
      

  6.   

    关键要看你的索引的情况。 (建议楼主不要浪费大家时间,贴出你实际的语句)-- 1 ---  b. 是哪儿来的?
    select id ,email 
    from user 
    where email in (
    select b.email 
    from user 
    where trim(ifnull(b.email,''))  <>''
    group by b.email 
    having count(*)>=2
    )
    order by email
    -- 2 ---  
    select id ,email 
    from user inner join (
    select email 
    from user  
    where trim(ifnull(b.email,''))  <>''                   -- 在B未定义前就引用,语法有问题。
    group by b.email 
    having count(*)>=2) b
    on a.email=b.email 
    order by email-- 3 ---
    select id ,email 
    from user a
    where exists (
    select 1 from user
    where email=a.email and id != a.id
    )
      

  7.   

    select id ,email 
    from user 
    where email in ( 
    select email 
    from user 
    where trim(ifnull(email,''))  <>'' 
    group by email 
    having count(*)>=2 

    order by email -----确实前面多加了好多的 d.     这个问题说明了mysql 的子查询有很大的问题
    ------只能用inner join来解决