Two Connection Methods for tables in Oracle databases

Source: Internet
Author: User

This article describes two different connection methods for tables in Oracle databases. If you want to learn more about these two connection methods, you may wish to browse the relevant content of the following articles and believe it will bring you better comments or methods.

A table connection refers to the association between tables in an SQL statement to retrieve relevant data from one or more tables, in general, the table and table connections can be divided into four types: equal connection, external connection, unequal connection, and self-connection, this article mainly analyzes the four Connection Methods of Oracle tables from the following typical examples:

Equal connection

Two columns with the same meaning can be used to create equal join conditions.

Only rows with the same value in the two tables of the connected column will appear in the query results.

For example, query employee information and department information of the corresponding employee;

 
 
  1. SELECT * FROM EMP,DEPT;   
  2. SELECT * FROM EMP,DEPT   
  3. WHERE EMP.DEPTNO = DEPT.DEPTNO;  

REM displays information about employees whose salaries exceed 2000 and their department names.

External Connection

The other two connection modes of tables in Oracle databases are external connections. For external connections, "(+)" can be used in Oracle, 9i can use LEFT/RIGHT/full outer join, which will be introduced in detail in the following example. In addition to the information that matches the same connection condition, the information of a table that cannot match the same connection condition is displayed.

External connections are identified by (+.

A) left condition (+) = right condition;

In addition to displaying information that matches equal connection conditions, it also displays information that cannot match equal connection conditions in the table where the right condition is located.

This is also called "right Outer Join". Another representation method is:

SELECT... FROM table 1 right outer join table 2 on join conditions

B) left condition = right condition (+ );

In addition to displaying information that matches equal connection conditions, it also displays information that cannot match equal connection conditions in the table where the left condition is located.

This is also called "left Outer Join ".

SELECT... FROM table 1 left outer join table 2 on join conditions

Example: displays employee information and Department Information

Unable to display employee information without Department

Unable to display department information without employees

 
 
  1. --SELECT * FROM EMP,DEPT WHERE EMP.DEPTNO = 
    DEPT.DEPTNO;  

The above content describes the Two Connection Methods of tables in the Oracle database. I hope it will help you in this regard.

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.