Reputation: 397
I'm trying to insert data from 3 tables that holds data from CSV files into a meaningful warehouse table but don't know if my syntax is correct.
insert into warehouseTBL
select a.recordNum, b.fieldA, b.fieldB, c.fieldC, c.fieldD,
from ctrTable a, tableB b, tableC c
where a.recordNum = b.recordNum
and a.recordNum = c.recordNum
and a.someField = b.someField
and a.someField = c.someField
So should I use a nested select in the From clause so it look something like this:
from ctrTable a, (
select *
from tableB, tableC,
where tableB.recNum = tableC.recNum
) as d,
where a.recNum = d.recNum
Does the syntax even make sense?
Upvotes: 2
Views: 4224
Reputation: 2796
Use this query to insert the rows,
insert into warehouseTBL
select recordNum, fieldA, fieldB, fieldC,fieldD from
(select a.recordNum, b.fieldA, b.fieldB, c.fieldC, c.fieldD,
from ctrTable a, tableB b, tableC c
where a.recordNum = b.recordNum
and a.recordNum = c.recordNum
and a.someField = b.someField
and a.someField = c.someField)p
Upvotes: 4