Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use append(insert into) with join and check if not exists?

Status
Not open for further replies.

seher

Programmer
May 19, 2012
1
DE
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top