select * from a;
select * from b;
drop table a;
drop table b;
create table a (
id number(10),
name varchar2(20)
)
create table b (
id number(10),
name varchar2(20)
)
insert into a values(1,’Priate’);
insert into a values(2,’Monkey’);
insert into a values(3,’Ninja’);
insert into a values(4,’Spaghetti’);
insert into b values(1,’Rutabaga’);
insert into b values(2,’Priate’);
insert into b values(3,’Derth’);
insert into b values(4,’Ninja’);
–内联合(inner join) 只生成同时匹配表A 和表B 的记录集。
select * from a
inner join b
on a.name=b.name;
–全外联合(full outer join)生成A 表和B 表里的记录全集,包括两边都匹配的记录。
–如果一边没有匹配的,缺失的这一边为null。
select * from a
full outer join b
on a.name=b.name;
select * from a,b where a.name=b.name;
–左外联合(left outer join)生成A 表中的所有记录,包括在B 表里匹配的记录。
–如果没有匹配的,右边将是null。
select * from a
left outer join b
on a.name = b.name;
select * from a,b where a.name=b.name(+);
–为了生成只在表A 里的而不在表B 里的记录集,同样用左外联合,然后用where语句排除不想要的语句。
select * from a
left outer join b
on a.name = b.name
where b.id is null;
–生成对于A 表和B 表 唯一记录集,我们用全外联合,然后用where语句排除两边都不想要的记录。
select * from a
full outer join b
on a.name=b.name
where a.id is null
or b.id is null;
–笛卡尔积//交叉联合(cross join) 把A 表中所有 连接到 B 表。
select * from a
cross join b;