update with two tables

0

I want to make an update to the reference table the field I want to update is the active_type and it is only in the table (active), which joins active and reference is the field (reference).

The active table has several example sequences (223,225,2654,455,530) and those sequences have an asset type that is (3) I want to change only 2 active sequences that are (455 and 530) but when I run the update updates everything I have that reference, I ask for help to make my update well.

  

table REFERENCE: reference fields
  ACTIVE table: reference fields, active_type, active_sequence

update REFERENCIA
set REFERENCIA.TIPO_ACTIVO = 4
WHERE
REFERENCIA.TIPO_ACTIVO = '3'
AND REFERENCIA IN
  (SELECT REFERENCIA
  FROM ACTIVO
  WHERE secuencia_activo in (455, 530) AND  REFERENCIA  = 2110260024  ) ;
    
asked by Angel Vosh 25.10.2016 в 00:50
source

1 answer

1

Maybe what you need is to make a inner join to the two tables, to remove the sub-sentence. But the explanation of the structure of your tables is not very clear.

I leave an example of how you would do with the update, maybe it is not exact to what you need, you would need to explain better the structure of the fields of your tables.

UPDATE  A
SET A.TIPO_ACTIVO = 4
FROM REFERENCIA A
INNER JOIN ACTIVO B ON A.REFERENCIA = B.REFERENCIA
WHERE B.SECUENCIA_ACTIVO IN (455,530) AND A.TIPO_ACTIVO = 3 AND B.REFERENCIA = 2110260024  
    
answered by 25.10.2016 в 22:26