I have a table(T1) which contains 2 columns(from,to), I have T2 which is a copy of T1 but it has 1 more column (Length) initially all values in this column is 1.
I want to append the result of inner join of T1 and T2 On T1.to= T2.from to T2 and put the length 2 for these also I want to check if there is any same row exists before between length 1, then do not append it with length 2, After this I want to do join just the values with 2 from T2 that I inserted them again with T1 to find length 3s, again check not exists and continue.
I am doing first join with this code:
INSERT INTO T1( From, To, length)
SELECT DISTINCT T1.From AS From, T2.TO AS To, 2 AS length
FROM T1 INNER JOIN T2 AS ON T1.To=T2.From;
But for continue and check not exists I do not know how should I do it.
I want to append the result of inner join of T1 and T2 On T1.to= T2.from to T2 and put the length 2 for these also I want to check if there is any same row exists before between length 1, then do not append it with length 2, After this I want to do join just the values with 2 from T2 that I inserted them again with T1 to find length 3s, again check not exists and continue.
I am doing first join with this code:
INSERT INTO T1( From, To, length)
SELECT DISTINCT T1.From AS From, T2.TO AS To, 2 AS length
FROM T1 INNER JOIN T2 AS ON T1.To=T2.From;
But for continue and check not exists I do not know how should I do it.