MYSQL联盟从左到右和组

时间:2014-01-19 01:36:14

标签: mysql union

我有一个包含两个表forum_postsforum_replies的论坛。我需要获得最活跃的用户。这是我最近尝试过的事情

                SELECT forum_reply.added_by, forum_posts.added_by FROM forum_reply  LEFT JOIN   forum_posts     ON  forum_posts.added_by = forum_reply.added_by 
                UNION 
                SELECT forum_posts.added_by, forum_reply.added_by FROM forum_posts  RIGHT JOIN   forum_reply    ON  forum_reply.added_by = forum_posts.added_by 

                WHERE forum_reply.date_added < '".$now."' AND forum_reply.date_added > '".$past24h."' AND forum_posts.date_added < '".$now."' AND forum_posts.date_added > '".$past24h."'

                GROUP BY forum_reply.added_by, forum_posts.added_by ORDER BY COUNT(*) DESC LIMIT 5");

问题是这个查询只给了我一个结果而不是5.结果肯定不是真的,因为这个查询给我的用户在过去24小时内没有发布任何内容。

0 个答案:

没有答案