帮助优化子查询
此查询获取与其他新闻文章类似标记的新闻文章。我是否可以消除这些我没有看到的子查询之一?
SELECT id,
title,
comment_count
FROM NEWS
WHERE (franchise_id = 1 OR franchise_id = 0)
AND draft = 0
AND id != 459
AND id IN (SELECT news_id
FROM news_tag_association
WHERE tag_id IN (SELECT tag_id
FROM news_tag_association
WHERE news_id = 459))
LIMIT 0, 5;
This query fetches news articles that are tagged similarly to other news articles. Is it possible I can eliminate one of these subqueries that I'm not seeing?
SELECT id,
title,
comment_count
FROM NEWS
WHERE (franchise_id = 1 OR franchise_id = 0)
AND draft = 0
AND id != 459
AND id IN (SELECT news_id
FROM news_tag_association
WHERE tag_id IN (SELECT tag_id
FROM news_tag_association
WHERE news_id = 459))
LIMIT 0, 5;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,没有 GROUP BY 或类似的,所以你可以使用普通的自连接:
Yes, there is no GROUP BY or similar, so you can use normal self-joins: