tags:

views:

143

answers:

3

I need to achieve this

update [table]
set [column c] = ( select [column a] + ' ' + [column b] from [table] )

but I get this error message

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

How can I achieve the desired effect without the undesired results :)

Jim

+4  A: 

That's easy:

update table
set c = a + ' ' + b

This will update all rows in the table.

Andomar
Duh...thanks... :)
jim
+2  A: 

try adding a WHERE clause to the sub-query so it picks out only one row.

duffymo
Thanks for the tip
jim
+1  A: 

UPDATE table SET c= a+' '+b;-------this works if a,b,c are of char/var char data type.

If they are of number data type it gives error. Also check the length of C.for eg: if C varchar2(30),a varchar2(10) and b varchar2(15) it goes correct if the length of right hand side value is more it gives error.