Related Tags

2

Please login or register to vote for this query.

(click on this box to dismiss)

Gets the most commonly associated tags to a particular tag, by number of posts.

Science Fiction and Fantasy

Q&A for science fiction and fantasy enthusiasts

SELECT 
  Tags.TagName, 
  COUNT(*) AS [Number of associated posts],
  Tags.Count AS [All posts with this tag],
  format(1.0*count(*)/Tags.Count,'p') as [Percentage associated]
FROM PostTags
  INNER JOIN Tags
    ON Tags.Id = PostTags.TagId
WHERE 
  PostTags.PostId IN 
  (
    --Gets all the PostIds that have this tag
    SELECT DISTINCT PostId
    FROM PostTags
      INNER JOIN Tags
        ON Tags.Id = PostTags.TagId
    WHERE Tags.TagName = ##TagName:string##
  )
  AND Tags.TagName <> ##TagName:string##--Remove the tag you’re looking for from "related" search results.
GROUP BY Tags.TagName, Tags.Count
ORDER BY COUNT(*) DESC, Tags.Count, Tags.TagName

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results