Q&A about the site for gardeners and landscapers
-- Enter Query Title -- Enter Query Description set nocount on declare @TagSet table (TagPostID int) declare @TagSearch int = ##TagId## insert @TagSet select PostID 'PostId' from PostTags where TagID = @TagSearch set nocount off select t.Id, t.TagName, count(*) from PostTags pt join @TagSet ts on ts.TagPostID = pt.PostId join Tags t on pt.TagId = t.Id join Posts p on pt.PostId = p.Id where t.Id != @TagSearch group by t.Id, t.TagName order by 3 desc