1

hey everyone I have two different tables:

PS(size(primary key), price) Sales(....size,quantity, total_Price)

I tried to execute this statement:

 update Sales
                set total_Price = (select price from PS, Sales 
where Sales.size = PS.size )*Quantity;

but i get this error always

SQL0811N The result of a scalar fullselect, SELECT INTO statement, or VALUES INTO statement is more than one row.

I know that the error is because the sub query i used in the select statement returns more than one row, that's why i can't work. Can someone please help me solve this problem.

Twelfth
  • 7,070
  • 3
  • 26
  • 34
Alladin
  • 1,010
  • 3
  • 27
  • 45

2 Answers2

3

Why are you joining in another sales table? My guess is that:

update Sales s
    set total_Price = (select ps.price * s.Quantity
                       from PS 
                       where s.size = PS.size);

will do what you want. Since ps.size is unique you should not get a SQL0811N

Lennart - Slava Ukraini
  • 6,936
  • 1
  • 20
  • 32
-1

For starters you can:

UPDATE sales SET total_Price = PS.price * Quantity
from PS, Sales where Sales.size = PS.size

May not be a great idea - if there's more than one matching value it'll pick an arbitrary winner (and Lennart's answer would raise an error, which in fact may be best here). If size is 1-to-1 then this is equivalent to Lennart's answer.

bwperrin
  • 680
  • 5
  • 12