[wp-hackers] Recent Comments Plugins.
Denis de Bernardy
denis at semiologic.com
Wed Jul 20 18:31:12 GMT 2005
> It's probably a case where two queries would be better than one:
Or, more likely, where the aggregate is useless:
SELECT
posts.*
FROM
wp_posts as posts
INNER JOIN
wp_comments as comments
ON comments.post_ID = posts.ID
WHERE
comments.comment_approved = '1'
# and whatever else
GROUP BY
posts.ID # prevent a post to appear twice
ORDER BY
comments.comment_date DESC # works too
LIMIT 0,20
> mysql> EXPLAIN SELECT wp_posts . * , MAX( comment_date ) AS
> mysql> max_comment_date
> -> FROM wp_comments, wp_posts
> WHERE wp_posts.post_date <= '2005-07-19 13:38:31'
> -> WHERE wp_posts.post_date <= '2005-07-19 13:38:31'
> -> AND (
> -> wp_posts.post_status = 'publish'
> -> OR wp_posts.post_status = 'sticky'
> -> )
> -> AND wp_posts.post_password = ''
> -> AND wp_posts.ID = wp_comments.comment_post_ID
> -> AND wp_comments.comment_approved = '1'
> -> GROUP BY wp_posts.ID
> -> ORDER BY max_comment_date DESC
> -> LIMIT 0 , 20;
More information about the wp-hackers
mailing list