如图:
在wp_fans读取ID为1的FOLLOW的全部值,然后在WP_POSTS表中读取每个FOLLOW的最近的POST_TIME值,注意:每个FOLLOW值只输出一次(是按照POST_TIME的DESC顺序排序的。)如果某个FOLLOW值在WP_POSTS表中存在多个,也只输出POST_TIME最近的一个,如果wp_fans中的FOLLOW值不存在WP-POSTS表中则不输出。类似这种的:
mysql

解决方案 »

  1.   

    参考下贴中的多种方法http://blog.csdn.net/acmain_chm/article/details/4126306
    [征集]分组取最大N条记录方法征集,及散分....
      

  2.   

    SELECT * FROM wp_fans b inner join WP_POSTS a 
    on a.post_auther=b.FOLLOW
    WHERE not exists(select 1FROM WP_POSTS WHERE 
     a.post_auther=post_auther AND a.POST_TIME>POST_TIME) 
    and b.id=1
      

  3.   

    select  A.follow,(select post from wp_posts where  A.follow=post_author order by post_time desc limit  1)
    from wp_fans A
      

  4.   


    表1的follow并不能按照POST-DATE的时候进行排序哦
      

  5.   


    它不能按时间排序哦,而且会输出多个FOLLOW为1的行
      

  6.   

    贴建表及插入记录的SQL,及要求结果出来看看
      

  7.   


    为什么我添加了 post_status='publish'它还有把不是PULISH的也输出了?
      

  8.   


    不知道我改成这样子,哪个效率高:select  A.follow,(select ID from wp_posts where  A.follow=post_author and post_status='publish' order by post_date desc limit  1)as kk
    from wp_fans as A where A.id='10'  order by kk DESC