mysql查询使用php获取两次重复行

时间:2017-12-23 09:53:16

标签: mysql

SELECT bp.postID, bp.postTitle, bp.postSlug, bp.authorName,bp.coverPic, bp.postDesc, bp.postDate FROM blog_posts bp INNER JOIN blog_post_cats bpc ON bp.postID=bpc.postID INNER JOIN blog_cats bc ON bpc.catID=bc.catID WHERE bp.STATUS=1 AND catSlug="World-In-360" ORDER BY postID DESC

此查询两次获取每一行。对此有何帮助?

1 个答案:

答案 0 :(得分:-1)

您只需要添加GROUP BY

SELECT bp.postID, bp.postTitle, bp.postSlug, bp.authorName,bp.coverPic, bp.postDesc, bp.postDate 
    FROM blog_posts bp 
INNER JOIN blog_post_cats bpc 
    ON bp.postID=bpc.postID 
INNER JOIN blog_cats bc 
    ON bpc.catID=bc.catID 
WHERE bp.STATUS=1 AND catSlug="World-In-360" 
GROUP BY postID
ORDER BY postID DESC