Here is a sample table I made to better illustrate my problem:
Create Table SampleTable(
TableID int,
NumberRow nvarchar(500)
)
Insert into SampleTable Values(1, '15,21,23,41,44,5,50,59,6,')
Insert into SampleTable Values(2, '10,24,29,41,5,50,59,6,73,')
Insert into SampleTable Values(3, '10,15,21,24,29,33,41,50,59,60,61,62,66,73,')
Insert into SampleTable Values(4, '10,15,21,24,28,33,37,41,44,5,50,6,60,61,62,66,')
Insert into SampleTable Values(5, '15,24,33,41,5,6,61,62,66,73,')
TableID NumberRow
---------------------------------
1 15,21,23,41,44,5,50,59,6,
2 10,24,29,41,5,50,59,6,73,
3 10,15,21,24,29,33,41,50,59,60,61,62,66,73,
4 10,15,21,24,28,33,37,41,44,5,50,6,60,61,62,66,
5 15,24,33,41,5,6,61,62,66,73,
After that I wrote a self join query:
Select
t1.TableID AS ID1,
t2.TableID AS ID2,
t1.NumberRow AS Numbers1,
t2.NumberRow AS Numbers2
From SampleTable t1
inner join SampleTable t2
on t1.TableID = t2.TableID - 1
Order by t2.TableID asc
Which results in:
ID1 ID2 Numbers1 Numbers2
-------------------------------------------------------------------------------------
1 2 15,21,23,41,44,5,50,59,6, 10,24,29,41,5,50,59,6,73,
2 3 10,24,29,41,5,50,59,6,73, 10,15,21,24,29,33,41,50,59,60,61,62,66,73,
3 4 10,15,21,24,29,33,41,50,59,60,61,62,66,73, 10,15,21,24,28,33,37,41,44,5,50,6,60,61,62,66,
4 5 10,15,21,24,28,33,37,41,44,5,50,6,60,61,62,66, 15,24,33,41,5,6,61,62,66,73,
Now I want to make two columns that show a string of numbers that are unique to both of the columns (Numbers1 and Numbers2).
So far I haven't come up with any solutions. My other approach was to make numbers be in a column instead of a string, but I still couldn't figure out how I could resolve my problem.