Q&A for professional and enthusiast programmers
declare @postid int = ##postid:int## declare @userid int = ##userid:int## select c.id as [Comment Link] , c.postid as [Post Link] from comments c inner join posts p on p.id = c.postid where ( p.id = @postid or p.parentid = @postid) and c.userid = @userid union select null , id from posts p where (p.id = @postid or p.parentid = @postid) and p.owneruserid = @userid