mySQL - Can you do something similar to INDEX + MATCH?

0

Good morning,

I need to update data in bulk in mySQL tables. What I have:

Tabla1 => Donde quiero actualizar datos, tengo 2 columnas, ID1 y VIEJOTEXTO.

Tabla2 => Una tabla con 2 columnas, ID1 y ID3.

Tabla3 => Tabla donde tengo que coger el dato, 2 columnas, ID3 y NUEVO TEXTO.

How can I do the UPDATE in the Tabla1 so that, depending on the relationship that exists in the Tabla2 , I update the "VIEJOTEXTO"(Tabla1) for "NUEVOTEXTO"(Tabla3) ?

Thank you very much!

    
asked by Nicolau Roca 28.12.2017 в 17:38
source

1 answer

0

Good!

Say with a solution, although I do not know if it is the most optimal (but it works!).

To relate 2 or more tables we create a query grouping all the tables indicating the relationship between each of them and with it we can assign the value of one field to another field, as if they were in the same table.

Code for the example provided in the question:

UPDATE 'tabla1' JOIN 'tabla2' ON tabla1.id1 = tabla2.id1 JOIN 'tabla3' ON tabla2.id3 = tabla3.id3 SET tabla1.viejotexto = tabla3.nuevotexto;

A thousand thanks to everyone, and I hope it will help more people;)

    
answered by 29.12.2017 в 09:34