user3649739
user3649739

Reputation: 1869

Insert with Multiple Joins

I figured out how to do a multiple table join update but am not clear how to set up as an Insert instead. This was my update:

  Update TableA as T1
  Inner Join TableB T2 
  Inner Join TableC T3
  On T3.A=T1.A and T3.B=T2.Band T1.C=T2.C
  Set T1.B=T3.B

Now I am trying to do the same thing except I want to insert vs updating a record. Is that possible?

Upvotes: 1

Views: 959

Answers (1)

sagi
sagi

Reputation: 40481

This is INSERT AS SELECT :

INSERT INTO Table1 (Col1,Col2,Col3.....)
SELECT t2.Col1,t3.Col2,t3.Col3....
FROM TableB t2
INNER JOIN TableC t3
 ON(t2.band = t3.b)

If you want to include/exclude some of Table1 data so add it to the joins as well.

Upvotes: 2

Related Questions