oracle聯查說明

2021-09-02 02:54:03 字數 1345 閱讀 6153

--建表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;

oracle級聯查詢

今天學習oracle 學到了乙個級聯語句 select from table start with 條件1 connect by prior 條件2 where 條件3例 select from usertable start with parent id 1 connect by prior or...

ORACLE關聯查詢

關聯查詢 多張表,而表與表之間是有聯絡的 是通過欄位中的資料的內在聯絡來發生 而不是靠相同的欄位名來聯絡的或者是否有主外來鍵的聯絡是沒有關係的 select dname,ename from emp,dept 笛卡爾積 無意義的 當2個表作關聯查詢的時候一定要寫關聯的條件 n個表 關聯條件一定有n ...

Oracle資料關聯查詢

關聯在oracle資料查詢時會經常用到,靈活的應用關聯可以解決很多實際應用的問題.下面給出一些示例 建表 create table ab ab id number 5 ab name varchar2 30 create table bb bb id number 5 bb name varchar...