SELECT qt.Id as [Post Link], JSON_VALUE(ph.Text, '$.Origi...

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

SELECT qt.Id as [Post Link], 
  JSON_VALUE(ph.Text, '$.OriginalQuestionIds[0]') as 'Original',
  CAST(JSON_VALUE(ph.Text, '$.OriginalQuestionIds[0]') AS INT) as  [Post Link], 
  pl.RelatedPostId [Post Link]
-- SELECT COUNT(*)
FROM(
  SELECT pl.PostId as Id
  FROM PostLinks AS pl
  WHERE pl.LinkTypeId = 3
  GROUP by pl.PostId 
  HAVING Count(*)=1
) AS qt
INNER JOIN PostHistory as ph on ph.PostId = qt.Id
                          AND ph.PostHistoryTypeId = 10 -- question closed
                          AND ph.Comment = 101 -- as a duplicate
                          
INNER JOIN PostLinks AS pl on pl.PostId = ph.PostId
                          AND pl.LinkTypeId = 3 -- duplicate
                          
INNER JOIN Posts AS p ON p.Id = pl.PostId

WHERE JSON_VALUE(ph.Text, '$.OriginalQuestionIds[0]') != pl.RelatedPostId
ORDER BY pl.CreationDate DESC

Enter Parameters

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