How can I use the UPDATE command between two tables?

0

I'm trying to update the GRUPO field from the ESTOQUE table to the value 1 (one) when the NCM field of the EST_ADICIONAIS table is equal to 21011000 . Therefore, both tables have the CODIGO field with equal values. I use firebird.

    
asked by anonymous 26.03.2015 / 15:49

2 answers

1

Based on the vague idea I have of your tables I've created a example to simulate your SQL statement.

I created the tables with the following structure:

  • STOCK (INT CODE, INT GROUP)
  • EST_ADITIONAL (INT CODE, NCM varchar (8))

I made the necessary inserts and, to update, as required, I executed the following SQL:

UPDATE ESTOQUE INNER JOIN EST_ADICIONAIS ON ESTOQUE.CODIGO = EST_ADICIONAIS.CODIGO AND EST_ADICIONAIS.NCM = '21011000' SET ESTOQUE.GRUPO = 1
    
26.03.2015 / 16:55
1

From what I understand, Washington, I believe this command will help you:

update estoque est 
set est.grupo = 1
where est.codigo in (
    select est_adi.codigo from est_adicionais est_adi where est_adi.ncm = '21011000'
)
    
21.05.2015 / 22:42