Help with UPDATE considering foreign keys in MYSQL

Asked

Viewed 13 times

0

Hello, good afternoon.

I’m trying to make a data change on a table that needs to work as follows:

I need to write a Query that UPDATE table 1, with the ID of table 2, but first, make sure to only do this, where the identification of the person (foreign key of a third table shared by the 2 Tables) is validated before.

TABLE 1 = links - TABLE 2 - history - TABLE 3 - persons

table 1 and table 2 share a foreign key from table 3, which is an ID.

table 1 has a foreign key which is the ID of table 2.

I can try to explain better, but in my head it is this, rs. I tried something like:

UPDATE vinculos
  SET id_historico = historico.id
    FROM historico
      WHERE = vinculos.id_pessoa = historico.id_pessoa;

But without much success...

  • I can’t figure out what you want to do. I’m supposed to update all entries in the link table or just a subset of them. If only a subset, what is the criterion for the update? Anyway your proposal mixes the syntax of an UPDATE with that of a SELECT.

No answers

Browser other questions tagged

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