0

I have a table which contains two columns, the first one contains a name and the second one contains a tag, so the name can have multiple tags, and the tags contains multiple names.

What I want to do is to write an SQL query that returns all the names that contains ALL the tags, which means that I must do AND operations in the SQL itself, my method takes a list that contains the tags, and it returns all the names that belongs to ALL tags, for example, If I passed 3 tags; A,B and C and there is a name has the tags: A and B, it will not be returned because it doesn't contains C.

hex
  • 515
  • 2
  • 4
  • 13

1 Answers1

0

I think that this will work:

SELECT Name FROM Table WHERE Tag IN ('list', 'of', 'tags') 
GROUP BY Name HAVING count(Name) = <counter of number of tags to Search>;
Tom11
  • 2,419
  • 8
  • 30
  • 56