MySQL查询转为多对多查询
我有一个查询,它返回一篇文章的所有信息,但我也想返回该文章所属的类别。我该怎么做?
表/列概述:
- 文章 - 文章 ID、发布日期、标题、摘要、内容
- 类别 - 类别 ID、标题 文章到类别 - 文章 ID、类别 ID
- 文章到类别 - 文章 ID、类别 ID
查询:
SELECT *,
UNIX_TIMESTAMP(publicationDate) AS publicationDate
FROM articles
WHERE article_id = :id
我尝试了一些不同的变体,但没有成功。
I have this query which returns all the information about an article but I also want to return which categories the article is in. How would I do that?
Table/Columns overview:
- articles - article_id, publicationDate, title, summary, content
- categories - category_id, title articles_to_categories - article_id, category_id
- articles_to_categories - article_id, category_id
Query:
SELECT *,
UNIX_TIMESTAMP(publicationDate) AS publicationDate
FROM articles
WHERE article_id = :id
I have tried a few different variations but no success.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试连接其他表:
您可能还想使用以下替代方法之一:
1。 GROUP_CONCAT
2。使用两个查询
使用现有查询,然后也使用以下查询:
Try joining the other tables:
You may also want to use one of the following alternative approaches:
1. GROUP_CONCAT
2. Use two queries
Use your existing query, then also use this one: