6

I'd like to run a search for questions containing a string (let's say foo for argument's sake) which have an answer that I've posted. I know I can run two separate queries for each half of this – "foo" is:question answers:1.. and is:answer user:me, but is there some way to combine these?

5

Looking at the search help, there doesn't seem to be a way to search a question that relates to specified answers like that.

You'll have to use either SEDE or the API.

Here's one way in SEDE:

SELECT     q.Id AS [Post Link],
           q.Score,
           q.Tags,
           q.Creationdate
FROM       Posts a
INNER JOIN Posts q
ON         q.Id = a.ParentId
WHERE      a.PostTypeId = 2 -- answer
AND        a.OwnerUserId = ##UserId:int##
AND        LOWER(q.Body) LIKE N'%' + LOWER(##SearchStr:string##) + '%'

Which you can See/Run live.


SEDE is only updated once per week. For fresher data, use the API -- but that's a fair bit more involved to code for something like this.

3

SEDE can do it. (I don't know why, but I couldn't find any existing queries that seemed apropos. Maybe no one bothered naming their throwaway queries; this is admittedly pretty simple SQL.)

select q.id as [Post Link],q.score as [Question Score],q.ViewCount,q.Tags,a.score as [Answer Score]
from posts q inner join posts a on a.parentid = q.id
where a.owneruserid = ##UserID:int##
and (q.body like '%' + ##SearchString:string## + '%'
 or q.title like '%' + ##SearchString:string## + '%')

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .