Try it this way, and see if it worked:
INSERT INTO pacientes_backup_novo(foto)
SELECT p.foto FROM pacientes p,
pacientes_backup pk
WHERE p.nome = pk.nome;
But before you do, make sure that the bank is empty, as it is an insert and not an update.
And check that the other fields accept null, otherwise you will not be able to execute this query.
Important: You are trying to make an insertion comparing a name that is in the two tables, IE, you will never get, because if both tables have data, you should not do Insert, but update the data.
If you only want to import photos from one table to another, you can do so:
update pacientes_backup bk set bk.foto = (
select foto from pacientes p inner join pacientes_backup in_bk on in_bk.nome = p.nome)
where bk.name = (
select nome from pacientes p inner join pacientes_backup in_bk on in_bk.nome = p.nome)
or:
UPDATE pacientes_backup pk
SET pk.foto =(SELECT p.foto FROM pacientes p WHERE p.nome = pk.nome)
Assuming that are all photos and that are in the same order. Can be so:
INSERT INTO pacientes_backup (foto) SELECT foto from pacientes
– Reginaldo Rigo
@Reginaldorigo, all right? So man, it’s because TABLE 2 has more records than TABLE 1...
– user175046