1

我有这个 SQL 查询来获取特定类别中的所有博客文章:

SELECT * FROM blogposts AS bp, blogpost_categories AS bpc
WHERE bpc.id_category = '3'
AND bpc.id_blogpost = bp.id
ORDER BY bp.date_published DESC

问题是,当我获取博客文章的 ID 号时,我得到的是类别 ID 号,这是错误的。

我该如何解决这个问题?

提前致谢。

4

1 回答 1

2

指定您想要的 ID(febp.idbpc.id.)并考虑使用 ajoin来澄清查询:

SELECT  bp.id as BlogPostId
,       bpc.id as CategoryId
FROM    blogposts AS bp
JOIN    blogpost_categories AS bpc
ON      bpc.id_blogpost = bp.id
WHERE   bpc.id_category = '3'
于 2012-12-31T14:21:39.640 回答