Q&A for peer programmer code reviews
;with lastrev_cte AS ( SELECT MAX(ph.Id) AS MaxId, p.Id AS pid FROM Posts p JOIN PostHistory ph ON ph.PostId=p.Id WHERE ph.PostHistoryTypeId in (2,5,9) GROUP BY p.Id ) SELECT TOP(##num?500##) pid AS [Post Link], ph.Text FROM lastrev_cte l INNER JOIN PostHistory ph ON l.MaxId=ph.id WHERE (ph.text Like '%##string?front.math.ucdavis.edu##%') ORDER BY pid DESC