What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 134 Stack Exchange communities.

Since we currently don't have a way to search our favorites, I built a SEDE Query to List of Favorites for a UserId that are Tagged with TagName.

The query takes two inputs:

  • UserId (int)
  • TagName (varchar)

However, I'm having problems doing a substring search on TagName within Posts.Tags.

SELECT Posts.id as [Post Link], Posts.Tags as [Tagged With]

FROM Votes, Posts

WHERE
     (Votes.PostId=Posts.Id) AND
     (Votes.VoteTypeId = 5) AND
     (Votes.UserId=##User:int##) AND
     ('##TagName##' LIKE Posts.Tags);

If a question tagged , Posts.Tags contains a string like this: <python><xml>.

No matter what I try for values of ##TagName##, I can only find questions with a single tag (see screenshot)...

Single-tag favorites

I have tried queries with the following TagName inputs:

  • <python> (returns favorites that have a single tag: python)
  • %<python>% (returns nothing)
  • %python% (returns nothing)

Perhaps I have misunderstood the format of the source, but I haven't figured out a better way to make the TagName queries. There are a lot of questions with multiple tags, but unless we have a wildcard (or substring) search capability on Posts.Tags, I'm not sure how we can get the right information.

Should I be able to do a wildcard search on Posts.Tags in SEDE? If so, how should I modify my existing query?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

I almost feel like this should have been a question on SO since its a problem with your SQL not Data.SE

Basically you've got your like clause backwards

Try

SELECT Posts.id as [Post Link], Posts.Tags as [Tagged With]

FROM Votes, Posts

WHERE
     (Votes.PostId=Posts.Id) AND
     (Votes.VoteTypeId = 5) AND
     (Votes.UserId=##User:int##) AND
     (Posts.Tags like '%##TagName##%' );​

Another approach is to use the denormalized tags table and not use the like clause at all if you just want question tagged with at least the as opposed to questions that have a tag that contains the word python (e.g. )

SELECT p.id as [Post Link], p.Tags as [Tagged With]
FROM  
        Votes v
        INNER JOIN Posts p
        ON v.PostID = p.id
        INNER JOIN PostTags pt
        ON p.id = pt.PostId
        INNER JOIN tags t
        on pt.TagID = t.ID
WHERE
     v.VoteTypeId = 5 AND
     v.UserId=##User:int## AND
     t.TagName = '##TagName##' ;​ --Only those tagged with Python (so ironPython will be ignored)
share|improve this answer
1  
That was it, thank you! Perhaps I should have posted on Stack Overflow, but I did not know enough SQL to realize that it was my query instead of a functionality gap in SEDE –  Mike Pennington Dec 12 '11 at 21:11

You must log in to answer this question.

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