1
Hello, I have these 3 tables in my database:
Table colaboradores
Table cursos
Table c_vendas_itens
I would like to make a Join of the three tables and save in another one, I can do this through the query below, but each time I have a new data in the table c_vendas_items I have to perform the Join again and then the data is duplicated, Does anyone know how I can resolve this situation? I am running this query in an insert Trigger in the table c_vendas_items.
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);
The data will be duplicated anyway, will be in the 3 tables and this auxiliary, so what is this other table? It’s some kind of backup?
– Costamilam
The field
cod_venda_item
is repeated in the tablec_venda_itens
or he’s a key Primary?– Pedro Paulo