Hello, I have these 3 tables in my database:
Table colaboradores
Table cursos
Table c_vendas_itens
I would like to do a join of the three tables and save to another one, I can do this through the query below, however every time I have a new data in the c_vendas_itens table I have to perform the join again and then the data gets duplicated, someone Do you know how I can solve this situation? I'm running this query on an insert trigger in the c_vendas_itens table.
INSERT INTO c_tabela_auxiliar
(
cod_venda_item,
status_venda,
cpf_colab,
cod_venda,
cod_curso,
nome_curso,
categoria_venda,
nome_colab,
banco,
dv,
agencia,
conta,
valor_venda_item,
valor_repasse_item
)
select
ven.cod_venda_item,
ven.status_venda,
cur.cpf_colab,
ven.codVenda,
cur.codCurso,
cur.nome,
cur.categoria,
col.nome,
col.banco,
col.dv,
col.agencia,
col.conta,
ven.valorVendaItem,
ven.valorRepasse
from c_vendas_itens as ven
inner join cursos as cur on (cur.codCurso = ven.cod_curso)
inner join colaboradores as col on (col.cpf = cur.cpf_colab);