I have table XYZ with following data
Id Name ssids
1 a1 1,2
2 a2 3
3 a3 4
4 a4 5
I am using cross-apply with two separated values and getting the same result, but it is causing duplicates.
And I don’t want to use distinct here. I just want to know what’s wrong with the below query.
Declare @Paravalue varchar(500)='1,2,3'
SELECT t.* FROM XYZ t
cross apply string_split(t.ssids, ',') ColumnIds
cross apply string_split(@Paravalue, ',') paraId
where paraId.value=ColumnIds.value
For above query getting output like below
Id Name ssids
1 a1 1,2
1 a1 1,2
2 a2 3
But i want result below without duplicate and i dont want to use distinct
Id Name ssids
1 a1 1,2
2 a2 3