MySql Update innerJoin

1

How do I make this query:

I have 3 tables A B and C

Table A is related to ID's of Table B .

I need to get the ids of B whose xcampo equals xcampo of C .

now you must update xcampo of A that contains the IDs that I just got from table B .

I already do it in the following way, I do a INNER JOIN of B and C , I export those ID'S and then I update the table A with a csv of those ID's but I would like to know if someone could have a more compact and faster formula.

I applied the chosen solution as the correct one (and it worked perfectly) my personal code stayed like this:

UPDATE pai_titulo AS a, 
     (
        SELECT
             pai.id ,update2.decreto
        FROM
            pai
        INNER JOIN
            update2
        On update2.cedula = pai.numero_documento
    ) AS b
set a.requerido_decreto_pep = b.decreto 
WHERE  a.id_pai = b.id
    
asked by Andress Blend 14.02.2017 в 16:10
source

1 answer

4

Guessing a bit about the structure of your tables, I would do it in the following way:

UPDATE table.a AS a, 
     (
        SELECT
            id,xcampo
        FROM
            B
        INNER JOIN
            C
        USING (xcampo)
    ) AS b
set a.xcampo = b.xcampo 
WHERE
        a.id = b.id
    
answered by 14.02.2017 / 16:20
source