The difference between left join and right join in Oracle talking about _oracle

Source: Internet
Author: User
Tags null null

In layman's terms:

The number of connections for a LEFT join B is the same as the number of records in Table A

A RIGHT join B has the same number of records as the number of records in table B

A LEFT join B equivalence B right join A

Table A:

Field_k, field_a

1 A

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 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 null 2 y

4 C 4 Z--

As an example:

Suppose the data in table A and table B are 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 the inner join in the connection query, and it produces the result

Two table-matched records appear in the results list.

According to the table above, the result is this

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 form of inner join, and its execution is the same as inner join

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

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

This is the left outer join or the right outer join in the outer join syntax

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

Select a.*,b.* from a LEFT join B on a.id=b.id

The result of the query is this:

a.ID name b.ID Stock

1 a 1 15

2 B 2 50

3 c NULL NULL

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

If it's a right outer join, it will show all the records in table B,

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

The result of the query is this:

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 top two. Left join is shorthand for left outer join

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

There is no such wording, wrong statement.

Related Article

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.