Skip to content

Instantly share code, notes, and snippets.

@airtonGit
Created May 15, 2019 13:37
Show Gist options
  • Save airtonGit/c0f4b830745a29f0e6502e22ba29a462 to your computer and use it in GitHub Desktop.
Save airtonGit/c0f4b830745a29f0e6502e22ba29a462 to your computer and use it in GitHub Desktop.
SQL inserir em tabela usando select em outra como origem das linhas
INSERT INTO tabelaDestino
SELECT null, campo1, campo2, CURRENT_TIMESTAMP, alias1.campoA
FROM tabelaOrigem
INNER JOIN tabelaRelacionada1 alias1 ON alias1.id = alias2.fk_id
WHERE
alias1.active = true
;
@airtonGit
Copy link
Author

Cenário usado: Adicionar 1 linhas para cada linha existente em tabela relacionada(tabelaOrigem) 1 pra 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment