Oracle Database basic learning (5) Multi-Table query, oracle Database

Source: Internet
Author: User

Oracle Database basic learning (5) Multi-Table query, oracle Database

Multi-Table query:Two or more tables are required for the query result. Multi-table join is required to generate multi-Table query.

 

1. Internal Connections (equivalent connections)

 

Example: display the contents of a connected table

select * from dept d, emp e where d.deptno = e.deptno;

Note: The content is displayed only when the d. deptno = e. deptno condition is met. Otherwise, the content is not displayed.

 

2. Outer Join: Let the equivalent value determine that data on both sides of the left and right can all be displayed, and use the "(+)" when using the outer join method )"

Format:

Left Outer Join: field = field (+)

Outer right join: Field(+)= Field

 

Example: display the employee name, position, and lead name

 

Analysis:

Confirm the data to be used:

 

1. employee name in the emp table, position (alias: e)

 

2. Lead name of the emp table (alias: m)

 

Confirm the connection relationship:

 

E. mgr = m. empno;

 

If an employee has no leadership, its content will not be displayed. In this case, an external connection is required, so that the table on one side can be displayed without leadership.

The left and right outer connections can be separated, but the most important thing is to display the content to be displayed.

 

select e.ename, e.job, m.enamefrom emp e, emp m where e.mgr = m.empno(+);

 

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.