Update with JOIN in Mysql

Asked

Viewed 821 times

1

I am updating to table A which will receive values from Table B

in accordance with a.codigo = B.folha When you run the routine below, it is slow and nothing happens for a long time. It is 500,000 lines. It’s normal or I have to wait or the script is wrong... I don’t know what to do in the routine in fact I have to bring information from B to A according to the condition.

UPDATE escrituras t1 INNER JOIN 
       imovel t2 ON t2.LIVRO = t1.CODIGO
   SET  
         t1.TipoImovelDescr = t2.DESCRICAO;
            a.RUA            =  b.RUA;
            a.BAIRRO      =  b.BAIRRO,
            a.MUNICIPIO = b.CIDADE,
            a.UF               = b.ESTADO
  • 1

    What is a and b? Is not defined in query.

1 answer

2


The query has some syntax errors like aliases a and b a dot and comma left on the first line after the set, your query should look like this.

UPDATE escrituras t1 INNER JOIN 
       imovel t2 ON t2.LIVRO = t1.CODIGO
   SET  
      t1.TipoImovelDescr = t2.DESCRICAO,
      t1.RUA = t2.RUA,
      t1.BAIRRO =  t2.BAIRRO,
      t1.MUNICIPIO = t2.CIDADE,
      t1.UF = t2.ESTADO

Maybe the problem is the lack of a WHERE some banks cancel these update/delete instructions as this may cause a damage, imagine updating the descriptions/categories of all products to sal/condimentos. In mysql you can enable this by adding this line before your main query:

SET SQL_SAFE_UPDATES=0;
  • I’m already running the script rray.thank you so much so far..

  • What was the problem with Where?

  • I don’t think so.

Browser other questions tagged

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