Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use right join in SQL statement

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

How to use right join in SQL statement? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Right join is the type of query in the SQL language, that is, join query. Its full name is right external connection (right outer join), which is a kind of external connection. A connection can usually be established in the from clause or the where clause of a select statement.

Where join_table indicates the name of the table participating in the join operation, which can be operated on either the same table or multiple tables. Joins that operate on the same table are called self-joins.

On (join_condition) is used to refer to join conditions, which consists of columns in the joined table and comparison operators, logical operators, and so on.

The SQL RIGHT JOIN syntax is as follows:

SELECT column_name (s) FROM table1RIGHT JOIN table2ON table1.column_name=table2.column_name

Or

SELECT column_name (s) FROM table1RIGHT OUTER JOIN table2ON table1.column_name=table2.column_name

For example, Table An is recorded as follows:

AID aNum

1 a20050111

2 a20050112

3 a20050113

4 a20050114

5 a20050115

Table B is recorded as follows:

BID bName

1 2006032401

2 2006032402

3 2006032403

4 2006032404

8 2006032408

SQL statement: select * from A right join B on A.aID = B.bID

The results are as follows:

AID aNum bID bName

1 a20050111 1 2006032401

2 a20050112 2 2006032402

3 a20050113 3 2006032403

4 a20050114 4 2006032404

NULL NULL 8 2006032408

(the number of rows affected is 5)

The results show that:

Right join is based on the records of table B, A can be regarded as the left table, B can be regarded as the right table, and right join is based on the right table. In other words, all the records in table B on the right will be represented, while table An on the left will only show records that meet the search criteria (in this case: A.aID = B.bID). The deficiency recorded in Table An is NULL.

This is the answer to the question about how to use right join in the SQL sentence. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report