原来在sql中是这样的
select top 9 softid,softname,a.channelid,softintro,b.content from PE_soft as a left join(select a.* from PE_Comment as a inner join (select  max(CommentID)  as  CommentID  from  PE_Comment  group  by  InfoID) as b on a.CommentID=b.CommentID) as b  on b.InfoID=a.softID where  Status=3 and Deleted={$PE_False}  order by softID desc作用是查询PE_soft中的数据,并且显示PE_Comment中有关联的数据(只显示最后的一条),上面这条也是在csdn里问到的我照葫芦画瓢
搬到mysql中
写了个这
select `title`,`msg`,`aid` from 52cms_archives as a left join((select a.* from 52cms_feedback as a inner join (select max(aid)  as  aid  from  52cms_feedback  group  by  aid ) as b on a.aid=b.aid) as b)  on (b.aid=a.id) order by senddate desc
发现过滤重复失效了,是max(aid)  as  aid  不对吗?我换成了ount(distinct aid)  as  aid,结果过滤掉了所有52cms_feedback中的数据,数据库没啥上传,高手凑合看下,看看是不是有什么函数没写对

解决方案 »

  1.   

    select `title`,`msg`,`aid` 
    from 52cms_archives as a 
    left join (select c.* 
               from 52cms_feedback as c 
               inner join (select max(aid)  as  aid  
                            from  52cms_feedback  
                           group  by  aid 
                           ) as b 
               on c.aid=b.aid
               ) as d 
    on (d.aid=a.id) 
    order by senddate desc 
      

  2.   

    select softid,softname,a.channelid,softintro,b.content from PE_soft as a left join
    (select a.* from PE_Comment as a inner join 
    (select  max(CommentID)  as  CommentID  from  PE_Comment  group  by  InfoID) as b on a.CommentID=b.CommentID) as b  on b.InfoID=a.softID where  Status=3 and Deleted=($PE_False)  order by softID desc limit 9