Skip to content

Instantly share code, notes, and snippets.

@monodot
Created October 29, 2017 11:42
Show Gist options
  • Save monodot/3f64869629236fe1470c1f293b6e5d5d to your computer and use it in GitHub Desktop.
Save monodot/3f64869629236fe1470c1f293b6e5d5d to your computer and use it in GitHub Desktop.
Stack Overflow: find questions matching multiple tags
SELECT TOP 100
Questions.Id
AS [Post Link],
Questions.Title,
Questions.AnswerCount,
Questions.ViewCount,
Questions.FavoriteCount,
Questions.Score,
Questions.LastActivityDate,
Questions.CreationDate
FROM Posts AS Answers
INNER JOIN Posts AS Questions
ON Questions.Id = Answers.ParentId
INNER JOIN Users AS Users
ON Answers.OwnerUserId = Users.Id
INNER JOIN PostTags
ON PostTags.PostId = Answers.ParentId
INNER JOIN Tags
ON Tags.Id = PostTags.TagId AND Tags.TagName IN ('tag1', 'tag2')
--WHERE
--Questions.CreationDate >= DATEADD(mm, -12, GETDATE())
GROUP BY
Questions.Id,
Questions.Title,
Questions.AnswerCount,
Questions.ViewCount,
Questions.FavoriteCount,
Questions.Score,
Questions.LastActivityDate,
Questions.CreationDate
HAVING COUNT(DISTINCT Tags.TagName) = 2
ORDER BY ViewCount DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment