0
In a table, I need to enter the value 'ID Related Assembly' in a field, with the following condition:
- This value can only be entered when the value of the "Id_table1" field is equal to the values that are in a field ("Id_table2") 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 am using the operator "=", I would like to know how I can condition this insert to the comparison of the 2 fields.
Can you share more information about your table structure? Without being sure of the structure, my best suggestion is to use the
IN
instead of the=
.– Leite
I just did that, solved my problem. I’m new to SQL and didn’t know the IN command... Thanks!!! :)
– Gabriel Marques
Good! I posted as an answer if you want to accept. In case someone has a similar problem in the future.
– Leite