Am I being stalked?

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 p.id as [Post Link],
  p.ownerUserId as [User Link],
  count(uc.userid) as [User Comments],
  count(sc.userid) as [Stalker Comments]
from Posts p
join comments uc on p.id = uc.postId and uc.userid = ##UserId##
join comments sc on p.id = sc.postId and sc.userid = ##StalkerId##
group by p.id, p.ownerUserId
union
select p.id as [Post Link],
  p.ownerUserId as [User Link],
  0 as [User Comments],
  count (sc.userId) as [Stalker Comments]
from Posts p
join comments sc on p.id = sc.postId and sc.userid = ##StalkerId##
where p.ownerUserId = ##UserId##
and p.id not in (
  select postId from comments where userId = ##UserId##)
group by p.id, p.ownerUserId
order by [Stalker Comments] desc, [User Comments] desc

Enter Parameters

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