开发者

Insert from multiple tables

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开发者_StackOverflow中文版 sense?


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜