Update a value in a column with conditional comparing 2 columns of 2 different tables

0

In a table, I need to enter the 'Assembly-Related ID' value in a field, with the following condition:

  • This value can only be entered when the value of the "Table1_ID" field is equal to the values that are in one field ("table_id2") of another table.

This is the code I'm using:

UPDATE tabela1 SET _Montagem = 'ID Relacionado Montagem' WHERE 
bancodb.dbo.tabela1.Id_tabela1 = (SELECT Id_tabela2 FROM tabela2)

SQL is returning me the following error:

A subconsulta retornou mais de 1 valor. Isso não é permitido quando a subconsulta segue um =, !=, <, <= , >, >= ou quando ela é usada como uma expressão.
Most likely because I'm using the "=" operator, I'd like to know how I can do to condition this insert to the comparison of the 2 fields.

    
asked by anonymous 14.06.2018 / 15:22

1 answer

1

Without being sure of the structure, my best suggestion is to use IN instead of = .

    
14.06.2018 / 15:34