gpt4 book ai didi

mysql查询相关文章

转载 作者:行者123 更新时间:2023-11-29 02:04:15 25 4
gpt4 key购买 nike

我有以下表格:

  • 文章 (idArticle)
  • 文章标签 (idArticle, idTag)
  • 标签 (idTag)

我想获取所有与文章“5”具有相同标签的文章,我正在尝试:

SELECT DISTINCT Article.*
FROM Article
INNER JOIN ArticleTag ON Article.idArticle = ArticleTag.idArticle
AND ArticleTag.idArticle = "5"
WHERE 1 = 1
ORDER BY title
LIMIT 40

但它显示了所有文章,而不是相关文章。

最佳答案

尝试

select a.* from Article a
inner join ArticleTag at
on at.idArticle = a.idArticle
where at.idTag in (select idTag from ArticleTag where idArticle =5)

select a.* from Article a
inner join ArticleTag at on at.idArticle= a.idArticle
inner join ArticleTag at2 on at2.idTag = a.idTag and at2.IdArticle! = at.idArticle
where at2.idArticle = 5

关于mysql查询相关文章,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9356686/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com