Skip to content

Instantly share code, notes, and snippets.

@hailwood
Created July 6, 2015 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hailwood/17817d1fb1d144303358 to your computer and use it in GitHub Desktop.
Save hailwood/17817d1fb1d144303358 to your computer and use it in GitHub Desktop.
SELECT SiteTree.`ID`, COUNT(KnowledgeBaseArticle.`ID`) AS TagMatches FROM KnowledgeBaseArticle
JOIN SiteTree ON KnowledgeBaseArticle.`ID` = SiteTree.`ID`
JOIN KnowledgeBaseArticle_Tags ON KnowledgeBaseArticle_Tags.`KnowledgeBaseArticleID` = KnowledgeBaseArticle.`ID`
JOIN KnowledgeBaseTag ON KnowledgeBaseArticle_Tags.`KnowledgeBaseTagID` = KnowledgeBaseTag.`ID`
WHERE KnowledgeBaseTag.`Title` IN ('apples', 'oranges')
GROUP BY KnowledgeBaseArticle.id
ORDER BY TagMatches DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment