Search code examples
tagsdataexplorer

Find questions with multiple tags (AND, not OR)


How can I find questions that are tagged with multiple tags, for example, BOTH AND ?

I've found answers on meta about using the browser to search multiple tags, but this question is specific to the SEDE: https://data.stackexchange.com

In the table Posts, the column Tags are stored as ncharv(250) and tags are appended to the string (not stored as array). In the browser, it looks like this

enter image description here

I only need the question (and answer) text for some text mining, so I had tried going direct to the Posts table:

pseudo_sql

  • select * from Posts where Tags in (tag_list)

this returns tag1 OR tag2

  • select * from Posts p1 inner join Posts p2 ON p1.Tags in (tag1) AND p2.Tags in (tag2)

I've also tried a larger query based on this popular query.


Solution

  • For multiple tags, one inefficient way to use SEDE is multiple LIKE statements

    SELECT TOP 10 
     * 
    FROM Posts
    WHERE Tags LIKE ('%python%')
    AND Tags LIKE ('%regex%')
    

    This will get you also similar tags, for example, .

    To get only those tags and no fuzzy matching, use

    %<python>%
    

    permalink