Skip to content
Advertisement

How to do an UPDATE with several SELECT in value to update in MSSQL

I’m trying to update a value which is the result of 2 SELECT

I checked that the following request give me a column of several value :

select value from table1 where table1.id = (select value2 from table3 where table3 = Value3

When I tried the update MSSQL retruned me this error message :

I tried subquery with IN after ‘value’ is not working

Advertisement

Answer

The error you cite means that your subquery returns multiple values:

This is aproblem because you are comparing the dataset that comes from the above query to a single (scalar) value, and those two things cannot equate.

As mentioned by some comments, a better way to do UPDATEs involving multiple tables is to use a FROM clause like in your SELECT queries directly in the UPDATE:

Note that the above, if there are multiple matches for a single row of table2, will use the last value in the recordset for the value.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement