I have the following table which I'll call 'example'
id name last_name
01 Adam Adams
02 Bill Billo
03 Cathy McCathyson
I need to modify the table and end up with the following:
id name
01 Adam Adams
02 Bill Billo
03 Cathy McCathyson
For a single row, I know how to write this query:
UPDATE example SET name =
(SELECT name FROM example WHERE id = 01)+" "
+(SELECT last_name FROM example WHERE id = 01)
WHERE id = 01;
How do I modify this query such that it updates each row with that row's values, as in the example?
EDIT: I've updated my example since it confused the issue.
just make a transaction statement, with multiple update statement and commit. In error case, you can just rollback modification handle by starting transaction.
The UPDATE statement in SQL is used to update the data of an existing table in database. We can update single columns as well as multiple columns using UPDATE statement as per our requirement. UPDATE table_name SET column1 = value1, column2 = value2,...
UPDATE example SET NAME = NAME + ' ' + last_name
ID NAME LAST_NAME
1 Adam Adams
2 Bill Billo
3 Cathy McCathyson
SQL> UPDATE example SET NAME = NAME + ' ' + last_name
2 /
3 rows updated
SQL> select * from example
2 /
ID NAME LAST_NAME
---------- -----------------------------------------
1 Adam Adams Adams
2 Bill Billo Billo
3 Cathy McCathyson McCathyson
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With