0
Your SELECT idlocal, uf_busca, cidade_busca FROM cursosprounine;
is returning the result as in the second image you posted, correct ?! Note that there is more than one record with the idlocal
with the value 2.
And you get the code with insert into local (idlocal, uf, cidade)
i.e.: You want to create a new record for the local table with the result of your SELECT.
However, for the idlocal primary key column of the local table you are trying to enter the value '2' and there is already a record with this id '2' in your local table.
That’s exactly what the error is telling you: "Duplicate primary key value '2'".
In order to be able to accomplish what you want, you should return only one result from your SELECT, try adding a GROUP BY idlocal, it would look like this:
INSERT INTO local(idlocal, uf, cidade) SELECT idlocal, uf_busca, cidade_busca FROM cursosprounine GROUP BY idlocal;
Thanks Caio, it worked, thanks!!!
– Igor gomes
I’m glad it worked ! Have it :)
– Caio Santos