Skip to content

Instantly share code, notes, and snippets.

@sduff
Last active March 24, 2021 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sduff/f93e42795362552390482414b44dbb5e to your computer and use it in GitHub Desktop.
Save sduff/f93e42795362552390482414b44dbb5e to your computer and use it in GitHub Desktop.
ANSI SQL Table joins and set operators - practice at https://livesql.oracle.com/
DROP table a;
DROP table b;
create table a (
aid NUMBER(10),
adiz VARCHAR2(10)
);
create table b (
bid NUMBER(10),
bdiz VARCHAR2(10)
);
insert into a (aid, adiz) values (1, 'A1');
insert into a (aid, adiz) values (2, 'A2');
insert into a (aid, adiz) values (3, 'A3');
insert into a (aid, adiz) values (4, 'A4');
insert into b (bid, bdiz) values (3, 'B3');
insert into b (bid, bdiz) values (4, 'B4');
insert into b (bid, bdiz) values (5, 'B5');
insert into b (bid, bdiz) values (6, 'B6');
select * from a;
select * from b;
select *
from a
cross join b;
select * from a
inner join b
on aid=bid;
select * from a
left outer join b
on a.aid=b.bid;
select * from a
right outer join b
on a.aid=b.bid;
select * from a
full outer join b
on a.aid=b.bid;
select aid as id from a
union
select bid as id from b;
select aid as id from a
union all
select bid as id from b;
select aid as id from a
intersect
select bid as id from b;
select aid as id from a
minus
select bid as id from b;
select * from
( select aid as id from a
minus
select bid as id from b
) union all (
select bid as id from b
minus
select aid as id from a
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment