Have we met?

1

Please login or register to vote for this query.

(click on this box to dismiss)

Where have I 'met' another user? (Reminder, Jon Skeet's user id is 22656 :) May throw up some false positives because of @Name matches.

Stack Overflow

Q&A for professional and enthusiast programmers

-- Have we met?
-- This will give the result of any questions asked or answer by a 
-- pair of users plus any question both users have answered.
-- Where have I 'met' another user? (Reminder, Jon Skeet's user id is 22656 :) May throw up some false positives because of @Name matches.

declare @MyId int = ##MyId##;
declare @TheirId int = ##TheirId##;

declare @MyName nvarchar(40)
select @MyName = DisplayName from Users where Id = @MyName

declare @TheirName nvarchar(40)
select @TheirName = DisplayName from Users where Id = @TheirId

-- Question/Answer meetings
  select
   Questions.Id as [Post Link],  
    case
      when Questions.OwnerUserId = @TheirId then @TheirName + '''s question was answered'
      when Questions.OwnerUserId = @MyName then @MyName + '''s question was answered'
    end as [Results]
  from Posts as Questions
  inner join Posts as Answers 
   on Questions.Id = Answers.ParentId
  where Answers.PostTypeId = 2 and Questions.PostTypeId = 1
   and ((Questions.OwnerUserId = @TheirId and Answers.OwnerUserId = @MyId)
     or (Questions.OwnerUserid = @MyId and Answers.OwnerUserId = @TheirId ))

union
-- Answers on same question
  select
   Questions.Id as [Post Link], 'Answered the same question' as [Results]
  from Posts as Questions
   inner join Posts as Answers 
   on Questions.Id = Answers.ParentId
  inner join Posts as MoreAnswers 
   on Questions.Id = MoreAnswers.ParentId
  where Answers.PostTypeId = 2 and MoreAnswers.PostTypeId = 2 
  and Questions.PostTypeId = 1
   and ((Answers.OwnerUserId = @TheirId and MoreAnswers.OwnerUserId = @MyId )
     or (Answers.OwnerUserid = @MyId and MoreAnswers.OwnerUserId = @TheirId ))

order by [Post Link]

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results