Q&A for spacecraft operators, scientists, engineers, and enthusiasts
; with revisions_cte as ( SELECT DISTINCT p.Id AS pid, ph1.Id AS phId FROM PostHistory ph1 INNER JOIN Posts p ON ph1.PostId=p.Id WHERE p.PostTypeId IN (##types?4,5##) and ph1.PostHistoryTypeId in (2,5,8) and ph1.Text Like '%##word?http:##%' and NOT(p.Body Like '%##word##%') ), firstrev_cte AS (SELECT pid, MIN(ph2.Id) as MinId FROM revisions_cte INNER JOIN PostHistory ph2 ON ph2.PostId=pid WHERE (ph2.Id>phId) AND ph2.PostHistoryTypeId in (2,5,8) AND NOT(ph2.Text Like '%##word##%') GROUP BY pid ) --- 2 = Initial Body - initial post raw body text --- 5 = Edit Body - modified post body (raw markdown) --- 8 = Rollback Body - reverted body (raw markdown) SELECT ---PostId AS [Post Link], concat( 'site://tags/', t.tagname, '/info|', t.tagname, ' ', case when p.posttypeid = 4 then 'excerpt' else 'wiki' end ) [Tag Link], revisions = 'site://posts/' + CAST(PostId AS varchar)+'/revisions', ph.UserId AS [User Link], ph.UserDisplayName, ph.CreationDate, ph.Comment FROM PostHistory ph INNER JOIN firstrev_cte ON ph.Id=MinId INNER JOIN Posts p ON p.Id=ph.PostId inner join tags t on (t.wikipostid = postid or t.excerptpostid = postid) ORDER BY ph.CreationDate DESC