Check for posts with same tag as a certain post

0

Please login or register to vote for this query.

(click on this box to dismiss)

Mythology Meta

Q&A about the site for enthusiasts and scholars of mythology and folklore

-- @PostId -> need to know id of post
DECLARE @PostId int = ##PostId##

SELECT DISTINCT p.Id, p.Title, p.Tags
FROM Posts p
INNER JOIN PostTags pt ON p.Id = pt.PostId
WHERE NOT EXISTS (
    SELECT 1
    FROM PostTags pt2
    WHERE pt2.PostId = @PostId AND pt2.TagId NOT IN (
        SELECT pt3.TagId
        FROM PostTags pt3
        WHERE pt3.PostId = p.Id
    )
)

Enter Parameters

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