Fórum Insert com select #328362
31/08/2006
0
bom galera é o seguinte:
tenho 3 tabela: [b:b4bfa9ed07]Tabela1, Tabela2, Tabela3[/b:b4bfa9ed07]
preciso fazer um [color=blue:b4bfa9ed07]Insert [/color:b4bfa9ed07]na [b:b4bfa9ed07]Tabela3 [/b:b4bfa9ed07]com os dados da [b:b4bfa9ed07]Tabela1 [/b:b4bfa9ed07]que não Existem na [b:b4bfa9ed07]Tabela2[/b:b4bfa9ed07]
obs: as Tabelas1 e Tabelas2 contem muitos registros, chega a ter mais de 50.000 registros.
qualquer sugestão será bem vinda
tenho 3 tabela: [b:b4bfa9ed07]Tabela1, Tabela2, Tabela3[/b:b4bfa9ed07]
preciso fazer um [color=blue:b4bfa9ed07]Insert [/color:b4bfa9ed07]na [b:b4bfa9ed07]Tabela3 [/b:b4bfa9ed07]com os dados da [b:b4bfa9ed07]Tabela1 [/b:b4bfa9ed07]que não Existem na [b:b4bfa9ed07]Tabela2[/b:b4bfa9ed07]
obs: as Tabelas1 e Tabelas2 contem muitos registros, chega a ter mais de 50.000 registros.
qualquer sugestão será bem vinda
Fabiano Góes
Curtir tópico
+ 0
Responder
Posts
31/08/2006
Cristiano Alves
Acho que seria algo + ou - assim
Insert into tabela3 (campo1,campo2,campo3)
(select t1.campo1,
t1.campo2,
t1.campo3 from tabela1 t1 where not Exists(Select Top 1 1 from tabela2 t2 where t1.campo1 = t2.campo1))
[]s
Insert into tabela3 (campo1,campo2,campo3)
(select t1.campo1,
t1.campo2,
t1.campo3 from tabela1 t1 where not Exists(Select Top 1 1 from tabela2 t2 where t1.campo1 = t2.campo1))
[]s
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)