7

How do I search for questions which only contains selected tags and nothing more?

For example, I need to see the question of which tags are only [c#] and [Winforms]. If I search for [c#] and [Winforms] tags it will list all questions which contain [c#] and [Winforms] tags. so It means the question may be tagged like this: [C#],[Linq],[SQL]; But I can not answer this question because it is also related to SQL.

I'm looking for questions those their tags are only and only [c#] and [Winforms] tags. Is this possible?

0

2 Answers 2

5

Just like Search for singleton tags on questions, it's currently only possible with a SEDE query.

But since there are many tags which don't have any influence on your ability to answer the question, it's probably better to focus on a few tags which you want to exclude, e.g.

[c#] [winforms] -[linq] -[sql]

(results)


You can fork the query to add additional constraints, like no answers at all or no accepted answer. If you're new to SEDE and/or SQL, don't forget to take the awesome tutorial which will help you getting started.

3
  • great query, but how about adding an option which user can only list unanswered questions or questions which have answers but none of them are accepted?
    – Nofuzy
    Commented Apr 16, 2019 at 12:06
  • See the last paragraph of the updated answer :)
    – Glorfindel Mod
    Commented Apr 16, 2019 at 12:14
  • Thanks for your update ;)
    – Nofuzy
    Commented Apr 17, 2019 at 5:31
4

In addition to the query from @Glorfindel, this query let you select all not closed questions that have an arbitrary number of tags. You can enter two, three, four tags separated by semi-colons.

-- will hold our selected tags
create table #selectedtags(value nvarchar(35) collate SQL_Latin1_General_CP1_CS_AS)

-- fill selectedtags based on the ; delimited tags 
insert into
#selectedtags
select rtrim(ltrim(value))
from string_split(##tags:string?winforms;linq##, ';')

-- select posts
select p.id as [Post Link]
     , p.creationdate
     , p.score
     , p.tags
from posts p
inner join posttags pt 
        on pt.postid = p.id  -- for each tag per post a row 
inner join tags t 
        on t.id = pt.tagid  -- which tag
inner join #selectedtags st 
        on st.value = t.tagname -- select the tags
-- check if the post doesn't have more tags
where (select count(*) 
       from posttags pc 
       where pc.postid = p.id) = (select count(*) 
                                  from #selectedtags)
and closeddate is not null
-- have the exact count of tags                                 
group by p.id 
     , p.creationdate
     , p.score
     , p.tags
having count(*) = (select count(*) 
                   from #selectedtags)

Keep in mind SEDE is only updated once a week, on Sunday.

2
  • great query, but how about adding an option which user can only list unanswered questions or questions which have answers but none of them are accepted?
    – Nofuzy
    Commented Apr 16, 2019 at 12:05
  • That is adding in the where clause: and (p.answercount = 0 or p.acceptedanswerid is null) I leave that as an exercise for the reader.
    – rene Mod
    Commented Apr 16, 2019 at 12:24

You must log in to answer this question.

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