日期:2014-05-16  浏览次数:20483 次

oracle联查说明
--建表table1,table2:
create table table1(id int,name varchar(10));
create table table2(id int,score int);

--删除表中的数据
delete from table1;
delete from table2;

--删除表
drop table table1;
drop table table2;
--添加talbe1数据
insert into table1 values (1,'lee');
insert into table1 values (2,'zhang');
insert into table1 values (4,'wang');

-- 添加talbe2数据
insert into table2 values (1,90);
insert into table2 values (2,100);
insert into table2 values (3,70);

--查询
select * from table1;
select * from table2;

--联查 (前面为 左表 后面为右表)

--1.外联查(左联查、右联查、完整联查)
--左联查
select * from table1 left join table2 on table1.id=table2.id;

--右联查
select * from table1 right join table2 on table1.id=table2.id;

--完整外联查询
select * from table1 full join table2 on table1.id=table2.id;

--2.内联查
select * from table1 join table2 on table1.id=table2.id;
-- 等价于  ( cross join 后面不能加on,只能加where)
select * from table1 cross join table2 where table1.id=table2.id;
--等价于
select a.*,b.* from table1 a,table2 b where a.id=b.id;

--3.交叉连接 (没有where的子语句,就会产生笛卡尔积现象)
select * from table1 cross join table2;
--等价于
select * from table1,table2;