Reputation: 43
I have a table Sample
with data stored like below:
Id | Name |
---|---|
1 | abc, def, ghi |
2 | cbc, deb, bbb, cbc |
3 | aaa, bbb, ccc |
4 | ddd, ddd, eee |
I need output like:
Id | Name |
---|---|
1 | abc, def, ghi |
3 | aaa, bbb, ccc |
Upvotes: 0
Views: 100
Reputation: 30023
A combination of EXISTS()
, STRING_SPLIT()
and an appropriate GROUP BY
clause is an option:
SELECT *
FROM Sample s
WHERE NOT EXISTS (
SELECT 1
FROM STRING_SPLIT(s.Name, ',')
GROUP BY RTRIM(LTRIM([value]))
HAVING COUNT(*) > 1
)
Upvotes: 1