Updating Column C with Column A and Column B values

I need to achieve this

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

      

but i am getting this error message

The subquery returns more than 1 value. This is not valid when the subquery follows = ,! =, <, <=,>,> = or when a subquery is used as an expression.

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

Jim

+1


a source to share


3 answers


It's easy:

update table
set c = a + ' ' + b

      



This will update all the rows in the table.

+5


a source


try adding a WHERE clause to the subquery so that it only selects one row.



+2


a source


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

If they are of a data type, it gives an error. Also check the length of C. For example: if C is varchar2 (30), varchar2 (10) and b is varchar2 (15), it will be correct if the length of the value on the right side is greater than it gives an error.

+1


a source







All Articles