Which tags used most with the entered tag

0

Please login or register to vote for this query.

(click on this box to dismiss)

Amateur Radio

Q&A for amateur radio enthusiasts

-- This query shows the most frequent tags used together with
-- the entered tag
-- the tag in question is always the first one (for obvious reasons)

DECLARE @TagName VARCHAR(255) = ##TagName:string##

Select TagId, TagName, TagCount FROM
(
Select Top(20) TagId, Count(TagId) As TagCount FROM
(
Select TagId FROM
(
Select Distinct PostId As PostId from PostTags 
Where TagId=(Select Id FROM Tags Where TagName=@TagName)
) PostsWithTag
Join PostTags AllPostTags On PostsWithTag.PostId=AllPostTags.PostId
) TagsUsed Group By TagId Order By TagCount Desc
) TagsOrdered Left Join Tags On Tags.Id=TagsOrdered.TagId 
Order By TagCount DESC

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results