Posts by a specific user where the last comment was made by another specific user

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

-- Created upon request from https://meta.stackexchange.com/users/377214/sonic-the-inclusive-hedgehog

-- PostUser: Posts by this user
-- CommentUser: Comments by this user


SELECT 
p.Id AS [Post Link],
(SELECT 
 TOP 1 c.Id 
 FROM Comments AS c 
 WHERE c.PostId = p.Id 
 ORDER BY c.CreationDate DESC) AS [Comment Link],
 p.CreationDate

FROM Posts AS p


WHERE p.OwnerUserId = ##PostUser##
AND (SELECT 
 TOP 1 c.UserId 
 FROM Comments AS c 
 WHERE c.PostId = p.Id 
 ORDER BY c.CreationDate DESC) = ##CommentUser##
 
 ORDER BY p.CreationDate DESC

Enter Parameters

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