Posts Oracle union keyword
Post
Cancel

Oracle union keyword

  • Create tables
1
2
3
4
5
6
7
create table CLIENT_TABLE_OLD(
    CLIENTID number(19)
);

create table CLIENT_TABLE_NEW(
    CLIENTID number(19) primary key
);
  • insert data into tables
1
2
3
4
5
6
7
8
9
10
11
insert into CLIENT_TABLE_NEW (CLIENTID) values(1);
insert into CLIENT_TABLE_NEW (CLIENTID) values(2);
insert into CLIENT_TABLE_NEW (CLIENTID) values(3);
insert into CLIENT_TABLE_NEW (CLIENTID) values(4);
insert into CLIENT_TABLE_NEW (CLIENTID) values(5);

insert into CLIENT_TABLE_OLD (CLIENTID) values(4);
insert into CLIENT_TABLE_OLD (CLIENTID) values(5);
insert into CLIENT_TABLE_OLD (CLIENTID) values(6);
insert into CLIENT_TABLE_OLD (CLIENTID) values(7);
insert into CLIENT_TABLE_OLD (CLIENTID) values(8);
  • Find all unique records that are present in both the tables
1
2
3
4
5
6
7
8
9
10
11
12
13
select clientid from CLIENT_TABLE_NEW
union
select clientid from CLIENT_TABLE_OLD;

CLIENTID
1
2
3
4
5
6
7
8

Cleanup

  • Drop tables
1
2
drop table CLIENT_TABLE_OLD;
drop table CLIENT_TABLE_NEW;
This post is licensed under CC BY 4.0 by the author.