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

What is the difference between the left connection and the right connection of MySQL database

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

Share

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

This article mainly introduces the MySQL database left connection and right connection what is the difference, has a certain reference value, friends in need can refer to. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

The difference between the left join and the right join in the database can be summarized as one sentence, that is, the left join where only affects the right table, and the right join where only affects the left table.

The difference between left connection (left join) and right connection (right join) in database

Left connection (Left Join)

Select * from tbl1 Left Join tbl2 where tbl1.ID = tbl2.ID

The result of the search after the left connection is to display all the data in tbl1 and the data in tbl2 that meet the where condition.

In short, Left Join affects the table on the right.

Right connection (Right Join)

Select * from tbl1 Right Join tbl2 where tbl1.ID = tbl2.ID

The result of the search is all the data in tbl2 and the data in tbl1 that meet the where condition.

In short, Right Join affects the table on the left.

Internal connection (inner join)

Select * FROM tbl1 INNER JOIN tbl2 ON tbl1.ID = tbl2.ID

It has the same function as select * from tbl1,tbl2 where tbl1.id=tbl2.id.

Other contents:

1. The connection statement used in the WHERE clause is called an implicit connection in the database language. INNER JOIN... The connection produced by the ON clause is called an explicit join. (other JOIN parameters are also explicit joins) there is no essential difference in the connection relationship between WHERE and INNER JOIN, and the result is the same. However, with the standardization and development of database language, implicit connection has been gradually eliminated, and the relatively new database language has basically abandoned implicit connection and adopted explicit connection.

2. No matter how you join, you can use the join clause, but when joining the same table, be careful to define an alias, otherwise an error will occur

(1) inner join: understood as "valid connection", only some data in both tables will display left join: if it is understood as "there is a left display", such as on a.field=b.field, it will show all the data in table an and the data in a\ b, and the data in An and B will be displayed in null.

(2) right join: understood as "there is a right display", such as on a.field=b.field, then all the data in table B and the data in a\ b are displayed, and the data in B and not in An are displayed in null.

(3) full join: understood as "full connection". All the data in the two tables show that it is actually inner + (left-inner) + (right-inner).

3. Join can be divided into three types of out-of-table joins: full outreach, left and right. Full outreach contains all the records of the two tables. The leftist couplet is dominated by the left table, the right one is secondary, and the right couplet is the opposite.

4. Generally speaking, the performance of database query statements should follow the following principles:

When doing a table-to-table join query, the big table is in front and the small table is in the

Do not use table aliases and distinguish fields in different tables by field prefixes

The constraints in the query conditions should be written before the table join conditions.

Try to use the fields of the index as query conditions

Thank you for reading this article carefully. I hope it is helpful for everyone to share the difference between the left connection and the right connection of the MySQL database. At the same time, I also hope that you can support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!

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