重复的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)
(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)
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
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
那就肯定有重复
ps:上面我的也写掉了group by ,不符合搂主要求,不改了
每一条日期都显示,当然重复,你的数据难道是每个 fromid 对应的纪录都是同一个 idate 值?既然 idate 是不重复的 distinct fromid,idate 自然只能取到不重复的 fromid 与 idate 的组合。