gpt4 book ai didi

mysql - super 复杂的SQL查询

转载 作者:行者123 更新时间:2023-11-29 14:49:19 25 4
gpt4 key购买 nike

有一个文章模型,每篇文章都有一个作者和发布者(都是表)。用户可以关注作者和出版商。

用户 -> 关注 -> 作者或出版商 -> 文章

我想查找他们关注的作者和出版商的所有文章。

SELECT articles.*, articles2.* FROM follows 
INNER JOIN articles ON follows.author_id = articles.author_id
INNER JOIN articles AS articles2 ON follows.publisher_id = articles2.publisher_id
WHERE follows.user_id = 1

我可以将所有文章放入 1 个查询中吗?如果是这样怎么办?如果没有,我可以合并两个查询然后对它们进行排序吗?

最佳答案

select a.* from follows f
inner join articles a on (a.author_id = f.author_id or a.publisher_id=f.publisher_id)
where f.user_id = 1

关于mysql - super 复杂的SQL查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6144270/

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