連接

鏈接查詢

創建兩張表做測試使用 s/e表

create table s (id number,name varchar2(32));
            insert into s values(1,'jack');
            insert into s values(2,'tom');
            insert into s values(3,'kity');
            insert into s values(4,'nono'); 
create table e (id number,grade number);
            insert into e values(1,56);
            insert into e values(2,76);
            insert into e values(11,8); 

查詢表如下:

SQL> select*from s;
ID NAME


     1 jack
     2 tom
     3 kity
     4 nono

SQL> select*from e;
ID GRADE


     1         56
     2         76
    11          8

內連接

 SQL> select s.id,s.name,e.grade from s inner join e on s.id=e.id;
    ID NAME                                  GRADE

     1 jack                                     56
     2 tom                                      76

左外連接

SQL> select s.id,s.name,e.grade from  s left join e  on e.id=s.id; 
    ID NAME                                  GRADE

     1 jack                                     56
     2 tom                                      76
     4 nono                             
     3 kity                             

右外連接

SQL> select s.id,s.name,e.grade from s right join e on s.id=e.id;
    ID NAME                                  GRADE

     1 jack                                     56
     2 tom                                      76
                                                 8

完全外鏈接

SQL> select s.id,s.name,e.grade from s full outer join  e on s.id=e.id;
    ID NAME                                  GRADE

     1 jack                                     56
     2 tom                                      76
     3 kity                             
     4 nono                             
                                                 8
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章