I have a database that contains project, keyphrase, article, and category
tables. Projects can have multiple keyphrases and multiple categories and so can articles. So I have respective join tables for each relationship.
I have a query that finds all of the articles that share both a keyphrase and a category with a specific project (i.e. 26).
SELECT DISTINCT article.id, article.summary
FROM article, articles_categories, articles_keyphrases
WHERE id = articles_categories.article_id AND id = articles_keyphrases.article_id
AND category_id IN (SELECT category_id FROM projects_categories WHERE project_id = 26)
AND keyphrase_id IN (SELECT keyphrase_id FROM projects_keyphrases WHERE project_id = 26)
I'm trying to find a different way to write this so that there aren't any sub queries. This is mostly just a learning exercise on my part because I would really like to see different approaches to this query.