用于检索特定类别的最后一个帖子的JOIN查询

时间:2011-11-03 00:24:01

标签: mysql wordpress

我有以下Wordpress代码:

SELECT terms.*, posts.ID as post_ID
FROM wp_terms terms 
JOIN wp_term_taxonomy term_taxonomy 
    ON terms.term_id = term_taxonomy.term_id
JOIN wp_term_relationships term_relationships 
    ON ( term_relationships.term_taxonomy_id = term_taxonomy.term_taxonomy_id 
        AND term_taxonomy.taxonomy = 'category' )
JOIN wp_posts posts
    ON ( posts.ID = term_relationships.object_id 
        AND posts.post_type='post'
        AND posts.post_status='publish')
WHERE terms.term_id=19 OR terms.term_id=20 OR terms.term_id=21 OR terms.term_id=22
GROUP BY terms.term_id
ORDER BY posts.post_modified_gmt DESC

我想从特定类别中检索最后一篇文章。但它返回每个类别的第一篇文章。我做错了什么?

1 个答案:

答案 0 :(得分:0)

尝试删除DESC关键字。