Common table Connection Methods in Oracle databases

Source: Internet
Author: User

We have introduced the Connection Methods of the first two tables in the Oracle database in two ways of table connection. The following article introduces the last two expressions of the Oracle database, the following describes the specific content of the article.

 
 
  1. SELECT * FROM EMP JOIN DEPT ON EMP.DEPTNO = DEPT.DEPTNO;   

REM displays employee information and corresponding department information, and displays department information without employee

 
 
  1. SELECT * FROM EMP,DEPT WHERE EMP.DEPTNO(+) = DEPT.DEPTNO;   
  2. SELECT * FROM EMP RIGHT OUTER JOIN DEPT ON EMP.DEPTNO 
    = DEPT.DEPTNO;  

REM displays employee information and corresponding department information, and displays employee information without Department

 
 
  1. SELECT * FROM EMP,DEPT WHERE EMP.DEPTNO = DEPT.DEPTNO(+);   
  2. SELECT * FROM EMP LEFT OUTER JOIN DEPT ON EMP.DEPTNO 
    = DEPT.DEPTNO;  

Unequal connection

The following describes the related content of the two tables in the last two expressions of the Oracle database. The two columns in the last two tables are not connected. The comparison symbol is generally>, <,..., BETWEEN .. AND ..

 
 
  1. REM SALGRADE   
  2. DESC SALGRADE;   
  3. SELECT * FROM SALGRADE;   

REM displays the employee's ID, name, salary, and level.

 
 
  1. SELECT EMPNO,ENAME,SAL,SALGRADE.* FROM SALGRADE,EMP   
  2. WHERE EMP.SAL BETWEEN LOSAL AND HISAL;  

REM displays employee ID, name, salary, salary level, and department name

 
 
  1. SELECT EMPNO,ENAME,SAL,GRADE,DNAME FROM EMP,DEPT,SALGRADE   
  2. WHERE EMP.DEPTNO = 
    DEPT.DEPTNO AND EMP.SAL BETWEEN LOSAL AND HISAL;  

Self-connection

Self-join is a frequently used connection method in databases. Using Self-join, you can treat an image of your own table as another table to get some special data. The following describes the self-connection method:

Copy one copy of the original table as another table, and connect the two tables to the same flute.

For example, the employee ID, name, and manager name are displayed.

 
 
  1. SELECT WORKER.ENAME,WORKER.MGR,MANAGER.EMPNO,
    MANAGER.ENAME FROM EMP WORKER,EMP MANAGER  
  2. WHERE WORKER.MGR = MANAGER.EMPNO;  

The above content is an introduction to the last two expressions of the Oracle database. I hope you will have some gains.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.