database - SQL - Add column data from one table into another while preserving original data -



database - SQL - Add column data from one table into another while preserving original data -

i need add together info 1 table (table1) table (table2) info in fullname column matches in both tables. code below want, except deletes of other info in table1's title column.

update table1 set title = (select title table2 table2.fullname = table1.fullname)

my goal update table1's title column have both info had plus info table2's title column without erasing info in table1's title column prior running sql query.

i'm assuming you're using oracle given syntax you've given. issue that, when utilize form of update statement, need where exists clause or similar:

update table1 set title = ( select title table2 table2.fullname = table1.fullname ) exists ( select 1 table2 table2.fullname = table1.fullname )

otherwise non-matching titles nulled out! reason result of subquery null when fullname doesn't exist in table2.

if concatenation you're looking (as @pm 77-1 comments above), you'll want following:

update table1 set title = title || ',' || ( select title table2 table2.fullname = table1.fullname ) exists ( select 1 table2 table2.fullname = table1.fullname )

hope helps.

sql database oracle

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -