日期:2014-05-18  浏览次数:20460 次

请高手帮忙看看下列语句 排除uid重复为什么无效?
请高手帮忙看看下列语句   排除uid重复为什么无效?

select   distinct(info.uid),user.lxr,user.tel,user.mobile_no,info.addtime   from   info,user   where   info.tg=1   and   info.uid=user.uid   order   by   info.addtime   desc

执行后,uid还是很多重复的,根本没有起得防重复的效果

------解决方案--------------------
try:

select
i.uid,u.lxr,u.tel,u.mobile_no,i.addtime
from
info i,user u
where
i.tg=1 and i.uid=u.uid
and
not exists(select 1 from info where uid=i.uid and tg=i.tg and addtime <i.addtime)
order by
i.addtime desc
------解决方案--------------------
select distinct(info.uid),user.lxr,user.tel,user.mobile_no,info.addtime from info,user where info.tg=1 and info.uid=user.uid order by info.addtime desc
union
select info.uid form info
------解决方案--------------------
建议LZ把两个表中的数据写出来,也把你要显示的结果给出来.这样我们才能帮到你,要不没有数据很难单凭文字就能说清楚的