Rightjoin SQL statement usage

Source: Internet
Author: User
Rightjoin: a query type in the SQL language, that is, join query. It is called rightouterjoin and is a type of outer join.

Right join: the query type in SQL, that is, join query. It is called right outer join, which is a type of outer join.

Table A records the following:

The code is as follows:
AID aNum
1 a20050111
2 a20050112
3 a20050113
4 a20050114
5 a20050115

Table B records the following:

The code is as follows:
BID bName
1 2006032401
2 2006032402
3 2006032403
4 2006032404
8 2006032408


The SQL statement is as follows:

The code is as follows:
SELECT * FROM
Right joing B
ON a. aID = B. bID

The result is as follows:

The code is as follows:

AID aNum bID bName
1 a20050111 1 2006032401
2 a20050112 2 2006032402
3 a20050113 3 2006032403
4 a20050114 4 2006032404
NULL 8 2006032408

(The number of affected rows is 5)

Result description:
After careful observation, we will find that the result of left join is exactly the opposite. this time, it is based on the right table (B) and is filled with NULL when Table A is insufficient.

Note the differences between on and where.

The ON statement is similar to the WHERE statement, but the ON statement is dedicated to join tables, the condition requirements and writing method after the ON statement are the same as those of the WHERE statement. you can basically use the ON statement as the WHERE 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.