leebongee
leebongee

Reputation: 103

How to insert data from multi tables to one table in Oracle?

I'd a trouble with inserting data from 3 table: A (id, name), B (id, name), C (id, name). They have the same field like that. How can I insert data from 3 tables above into table D (id, name)?

Upvotes: 1

Views: 26

Answers (1)

Pham X. Bach
Pham X. Bach

Reputation: 5442

You could use UNION or UNION ALL

INSERT INTO table_d(id, name)
SELECT id, name
FROM table_a
UNION ALL 
SELECT id, name
FROM table_b
UNION ALL 
SELECT id, name
FROM table_c;   

If you want to remove duplicate rows in 3 tables, change UNION ALL to UNION. Refer information about union vs union all

Upvotes: 4

Related Questions