Reputation: 64074
I have two tables:
TABLE_A
head1 head2
foo case1
bar case2
and TABLE_B
head1 head2
hux case1
pix case2
ilf case1
What I want to do is to create this table:
head1 head2
foo case1
bar case2
hux case1
pix case2
ilf case3
Namely just combine them, without removing any redundancy.
What's the right command to do it? I tried this but it didn't give the the desired result.
CREATE TABLE TABLE_AB(head1 text, head2 text)
(SELECT * FROM TABLE_A)
UNION ALL
(SELECT * FROM TABLE_B)
Upvotes: 1
Views: 34
Reputation: 238296
You can omit the parenthesis around the union parts. Also, for create table ... select
, you don't have the specify the column definitons.
create table Table3
select *
from Table1
union all
select *
from Table2
Upvotes: 1
Reputation: 2138
You may change the columns names to the desired ones.
CREATE TABLE TAB1 (ID number, NAME VARCHAR2(10));
CREATE TABLE TAB2 (ID number, NAME VARCHAR2(10));
INSERT INTO TAB1 VALUES (1, 'AAA');
INSERT INTO TAB1 VALUES (2, 'BBB');
INSERT INTO TAB1 VALUES (3, 'CCC');
INSERT INTO TAB2 VALUES (1, 'EEE');
INSERT INTO TAB2 VALUES (4, 'FFF');
CREATE TABLE TAB AS ((SELECT * FROM TAB1) UNION ALL (SELECT * FROM TAB2));
Upvotes: 1