-1

Please help, I'm having two tables Table_A and Table_B below, I would like to append data from Table_B to Table_A where Table_A.C1 = Table_B.C1. The Table_A final result below.

Table_A 
C1      | C2      
-------- ---------
1@a.com | e@a.com 


Table_B 
C1      | C2      
-------- ---------
1@a.com | abc@.com 

**FINAL RESULT**

Table_A 
C1      | C2      
-------- ---------
1@a.com | e@a.com; abc@.com 
jp2631
  • 39
  • 1
  • 8

3 Answers3

1
update ta
set ta.c2 = ta.c2 + ';' + tb.c2
from Table_A ta
inner join Table_B tb on tb.C1 = ta.c1
0

The first thing I would recommend is good database normalization, which may make the problem you are trying to solve moot. See Database Normalization

If your database is as normalized as possible, a better idea than what you have would be to leave Table A alone and create a view with rows made up of "matches" between Table A and Table B. It is very bad database form to have multiple values in a column.

Use: CREATE VIEW table_A_table_B AS SELECT * FROM Table_A JOIN Table_B ON Table_B.C1 = Table_A.C1.

The advantage of a view is that the view "table" will update every time either Table_A or Table_B is updated.

Community
  • 1
  • 1
Anthony Watson
  • 108
  • 1
  • 9
0

You can use ANSI MERGE:

MERGE table_a a
USING table_b b
ON a.c1 = b.c1
WHEN matched THEN
UPDATE SET a.c2 = a.c2 || ';' || b.c2;
Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76