Get all related tags by tag

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

DECLARE @tagId int = ##TagID##

SELECT Tags.TagName, COUNT(Posts.Id) as 'Count' FROM Posts
INNER JOIN PostTags as PT on Posts.Id = PT.PostId
INNER JOIN Tags on Tags.Id = PT.TagId
WHERE Posts.Id in (SELECT PT.PostId FROM PostTags as PT
                       WHERE PT.TagId = @tagId
                  ) and 
                  Tags.Id <> @tagId
GROUP BY Tags.TagName
ORDER BY 'Count' desc

Enter Parameters

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