I have to update a given field of a table by subtracting from it the values returned from a select in another table. The problem I am facing is that as select returns more than one value and I have to go subtracting value by value, so I can compare if the current value is less than the value of the query, I do not know how to do this. What I did of the error saying that the result has more than one value and can not execute.
update Produto2 set valor = case when (select p.valor from Produto p where p.clienteId = clienteId) < valor then
valor - (select p.valor from Produto p where p.id = produtoId) else
valor - 0 end;
And furthermore in the end I would have to update the second table by telling which data was used, but I do not know how to store the ids that were updated.