重复的fromid中,显示 idate 最大或最小的还是随意的一条?
 (select  distinct fromid,idate from newtoupiao)    ==> (select  distinct fromid,max(idate) as idate from newtoupiao)   or (select  distinct fromid,min(idate) as idate from newtoupiao) 
 

解决方案 »

  1.   

    select a.fromid,a.idate,b.username,c.title from (select fromid,max(idate) as idate from newtoupiao) a left join toupiao_pics b on a.fromid=b.userid left join toupiao_pics c on a.fromid=c.userid leftjoin newtoupiao d on d.fromid=b.userid where a.fromid  <>0  order by a.fromid  
      

  2.   

    1、加了这个字段 idate你又没用到,加了做啥
    2、
    select a.fromid,a.idate,b.username,c.title 
    from (select fromid,max(idate) as idate from newtoupiao group by fromid) a 
    left join toupiao_pics b on a.fromid=b.userid 
    left join toupiao_pics c on a.fromid=c.userid 
    left join newtoupiao d on d.fromid=b.userid 
    where a.fromid  <>0  order by a.fromid  
      

  3.   


    select a.fromid,a.idate,b.username,c.title from 
    (select fromid,max(idate)idate from newtoupiao) a
    left join toupiao_pics b on a.fromid=b.userid
    left join toupiao_pics c on a.fromid=c.userid 
    left join newtoupiao d on d.fromid=b.userid 
    where a.fromid  <>0  order by a.fromid  
      

  4.   

    之前写出的SQL错了,修正如下: (select  distinct fromid,idate from newtoupiao)    ==> (select fromid,max(idate) as idate from newtoupiao group by fromid)   or (select fromid,min(idate) as idate from newtoupiao group by fromid)
      

  5.   


    那就肯定有重复
    ps:上面我的也写掉了group by ,不符合搂主要求,不改了
      

  6.   

    select a.fromid,a.idate,b.username,c.title from (select  distinct fromid,idate from newtoupiao) a left join toupiao_pics b on a.fromid=b.userid left join toupiao_pics c on a.fromid=c.userid leftjoin newtoupiao d on d.fromid=b.userid where a.fromid  <>0  order by a.fromid  把你认为重复的数据比较下idate数据是否不同
      

  7.   


    每一条日期都显示,当然重复,你的数据难道是每个 fromid 对应的纪录都是同一个 idate 值?既然 idate 是不重复的 distinct fromid,idate 自然只能取到不重复的 fromid 与 idate 的组合。