Q&A for professional and enthusiast programmers
with firstrev_cte AS ( SELECT MIN(ph.Id) AS MinId, p.Id FROM PostsWithDeleted p JOIN PostHistory ph ON ph.PostId=p.Id WHERE (ph.Text LIKE '%<##tag##>%') AND (p.DeletionDate IS NOT NULL) AND (ph.PostHistoryTypeId in (3,6,9)) GROUP BY p.Id ) SELECT PostId AS [Post Link], url = 'site://posts/' + CAST(PostId AS varchar)+'/revisions', UserId AS [User Link], Comment AS [Edit Summary], Text AS [Tags] FROM PostHistory INNER JOIN firstrev_cte ON PostHistory.Id=MinId ORDER BY CreationDate DESC