SQL: Copy records from a column

Asked

Viewed 136 times

0

inserir a descrição da imagem aqui Using: Mysql I have this table called Licencas I need to get the column empresa_id and the coluna_id of this table

And pass this data from these two columns to another table Calling for condutors_empresas that contains the columns: empresa_id and condutor_id

I tried to pass this script below SQL but it did not work out which the correct form?:

 UPDATE condutors_empresas
LEFT JOIN licencas
SET condutors_empresas.empresa_id = licencas.empresa_id

But he returns this error to me:

#1064 - Você tem um erro de sintaxe no seu SQL próximo a 'SET condutors_empresas.empresa_id = licencas.empresa_id' na linha 3

Tabela condutors_empresas esta vazia

Table conductors_companies this empty need to pass the Licencas data to ca

  • 1

    But these company values_id already exist in the Call table? What are you updating? It would not be an INSERT of these two existing fields in the Licencas table in the Call table?

  • Not the table conductors_companies is empty, I need to take the data from the LICENCA table the column empresa_id and conductor_id take this data and pass to the table conductors_companies within the column empresa_id and conductor_id. I will put photo in the description the table conductors_companies

1 answer

0


If your table is empty then you should use an INSERT and not an UPDATE.

INSERT INTO condutors_empresas(empresa_id, condutor_id) SELECT DISTINCT empresa_id, condutor_id FROM Licencas;
  • It worked out, buddy, thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.