Differences between left join and right join in oracle

Source: Internet
Author: User

In layman's terms:

The number of records connected by A left join B is the same as that of Table.

The number of records connected by A right join B is the same as that of Table B.

A left join B is equivalent to B right join

 

Table:

Field_K, Field_A

1

3 B

4 c

Table B:

Field_K, Field_ B

1 x

2 y

4 z

Select a. Field_K, a. Field_A, B. Field_K, B. Field_ B

From a left join B on a. Field_K = B. Field_K

Field_K Field_A Field_K Field_ B

----------------------------------------

1 a 1 x

3 B NULL

4 c 4 z

Select a. Field_K, a. Field_A, B. Field_K, B. Field_ B

From a right join B on a. Field_K = B. Field_K

Field_K Field_A Field_K Field_ B

----------------------------------------

1 a 1 x

NULL 2 y

4 c 4 z --

For example:

Assume that the data in Table a and table B is like this.

A B

Id name id stock

1 a 1 15

2 B 2 50

3 c

Select * from a inner join B on a. id = B. id

This syntax is an internal connection in the connection query. The result is:

The matching records of the two tables are displayed in the result list.

According to the preceding table, the result is as follows:

A. id name B. id stock

1 a 1 15

2 B 2 50

----------------------------

Select * from a, B where a. id = B. id

This syntax is another method of writing internal join, and the execution result is the same as that of inner join.

--------------------------------

Select * from a left/right join B on a. id = B. id

This is the left Outer Join or right Outer Join in the outer join syntax.

If it is a left outer join, it will display all records in Table,

Select a. *, B. * from a left join B on a. id = B. id

The query result is as follows:

A. id name B. id stock

1 a 1 15

2 B 2 50

3 c null

--------------------------------------------

If it is a right outer join, it will display all the records in Table B,

Select a. *, B. * from a right join B on a. id = B. id

The query result is as follows:

A. id name B. id stock

1 a 1 15

2 B 2 50

--

Select a. *, B. * from a left join B on a. k = B. k

Select a. *, B. * from a left outer join B on a. k = B. k

---------- The above two types are the same. left join is short for left outer join.

Select a. *, B. * from a left inner join B on a. k = B. k

No such statement. It is a wrong statement.

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.