如何进行多表查询插入的操作??
把论坛爬了一轮,没有找到结果。=..=!
我有三张表A,B,C,表A中有2个字段AA1,AA2,B中有3个字段BB1,BB2,现在要求是这样:
如果BB1=AA1 AND BB2=AA2,就把BB1和BB2、BB3插入C表中的CC1和CC2以及CC3字段。。。。
------解决方案--------------------insert into c(CC1,CC2,CC3)
select b.BB1,b.BB2,b.BB3 from a,b where b.BB1=a.AA1 AND b.BB2=a.AA2
------解决方案--------------------insert into c(CC1,CC2,CC3)
select b.BB1,b.BB2,b.BB3
from a inner join b on b.BB1=a.AA1 AND b.BB2=a.AA2
where not exists(select 1 from c where a.cc1=b.bb1 and c.cc2=b.bb2 and c.cc3=b.bb3)