Reputation: 171
I'm trying to setup a SQL query where I want to get data by tags. The problem is that "Tags" column stores data in comma separated format, for example "tag1,tag2".
Code example:
SELECT * FROM News
WHERE (SELECT value FROM STRING_SPLIT(Tags, ','))
IN (SELECT value FROM STRING_SPLIT('tag1,tag2,tag3', ','));
Is it possible?
Upvotes: 0
Views: 252
Reputation: 1269443
You can use a subquery where you join the result sets together:
SELECT N.*
FROM News N
WHERE EXISTS (SELECT 1
FROM STRING_SPLIT(N.Tags, ',') s1 JOIN
STRING_SPLIT('tag1,tag2,tag3', ',') s2
ON s1.value = s2.value
);
Upvotes: 1