Oracle left and right connections

Source: Internet
Author: User

In Oracle, the left and right join statements in SQL Server are saved, and they are represented by a "(+.
In the following experiment, query 1 and query 2 are equivalent, and query 3 and query 4 are equivalent.

Query 1:
Select first_name, department_name, EMP. department_id from EMP, parameters Dept
Where EMP. department_id (+) = Dept. department_id;

122 rows selected.

Query 2:
Select first_name, department_name, EMP. department_id from orders ments dept left join EMP
On EMP. department_id = Dept. department_id;

122 rows selected.

 

 

Query 3:
Select first_name, department_name, EMP. department_id from EMP, parameters Dept
Where EMP. department_id = Dept. department_id (+ );

107 rows selected.

Query 4:
Select first_name, department_name, EMP. department_id from EMP left join partitions Dept
On EMP. department_id = Dept. department_id;

107 rows selected.

 

Summary:

1. Where is the (+) side, all records on the other side are returned.

2. (+) is placed on one side that contains null values. It cannot be used on both sides at the same time.

 

 

The supplementary inline method uses the Using Keyword:

Select first_name, department_name, department_id from EMP join orders ments dept using (department_id );

Note: The fields in using cannot contain aliases, and the fields in using in select_list cannot contain aliases. See the following two examples:

Select first_name, department_name, EMP. department_id from EMP join conditions dept using (EMP. department_id );
Using (EMP. department_id)
*
Error at line 2:
ORA-01748: only simple column names allowed here

Select first_name, department_name, EMP. department_id from EMP join conditions dept using (department_id );
Select first_name, department_name, EMP. department_id from EMP join statements Dept
*
Error at line 1:
ORA-25154: column part of using clause cannot have qualifier

 

Join using, which is equivalent to inner join

Select EMP. first_name, Dept. department_name, EMP. department_id from EMP join orders ments Dept
On EMP. department_id = Dept. department_id;

 

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.