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 implement join query by mysql

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

Share

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

Let me tell you a little bit about how to implement join query in mysql. Have you known about similar topics before? If you are interested, let's take a look at this article. I believe it will be of some help to you after reading how mysql implements the join query.

Cross-connect cross join:

There are no conditions, just the result of joining all data rows together according to the basic concept of connection. It's also called "Cartesian product".

For Table 1 (N1 fields, N2 rows), Table 2, (M1 fields, m2 rows), the result of their cross-join is:

There are n1+m1 columns

There are n2*m2 lines.

The forms are:

Select * from Table 1, Table 2

Select * from Table 1 join Table 2

Select * from Table 1 cross join Table 2

Example:

Results:

Internal connection inner join:

Form: select * from Table 1 [inner] join Table 2 on connection conditions

Example:

Results:

Note: although this kind of internal join query between a table and a table can be reflected as a "relationship" between a table and a table-- usually a foreign key relationship-- it does not require a foreign key relationship to use such a join.

You can set an alias for it using as:

Left (outside) connect left (outer) join:

Form:

Table 1 (left table) left [outer] join Table 2 (right table) on connection conditions

Meaning: in fact, it is the result of the inner join of two tables, plus the data of the left table that do not meet the conditions set by the inner join.

Example:

Results:

It can be seen that the results of the left connection and the data of the left table will be "all taken out".

Right (outside) connect right (outer) join:

Form:

Table 1 (left table) right [outer] join Table 2 (right table) on connection conditions

Meaning: it is actually the result of the inner join of two tables, plus the data of the table on the right that does not meet the conditions set by the inner join.

Example:

Results:

Join query

Is to "join" two or more tables as a data source and get the required data from it.

Cross-connect cross join:

There are no conditions, just the result of joining all data rows together according to the basic concept of connection. It's also called "Cartesian product".

For Table 1 (N1 fields, N2 rows), Table 2, (M1 fields, m2 rows), the result of their cross-join is:

There are n1+m1 columns

There are n2*m2 lines.

The forms are:

Select * from Table 1, Table 2

Select * from Table 1 join Table 2

Select * from Table 1 cross join Table 2

Example:

Results:

Internal connection inner join:

Form: select * from Table 1 [inner] join Table 2 on connection conditions

Example:

Results:

Note: although this kind of internal join query between a table and a table can be reflected as a "relationship" between a table and a table-- usually a foreign key relationship-- it does not require a foreign key relationship to use such a join.

You can set an alias for it using as:

Left (outside) connect left (outer) join:

Form:

Table 1 (left table) left [outer] join Table 2 (right table) on connection conditions

Meaning: in fact, it is the result of the inner join of two tables, plus the data of the left table that do not meet the conditions set by the inner join.

Example:

Results:

It can be seen that the results of the left connection and the data of the left table will be "all taken out".

Right (outside) connect right (outer) join:

Form:

Table 1 (left table) right [outer] join Table 2 (right table) on connection conditions

Meaning: it is actually the result of the inner join of two tables, plus the data of the table on the right that does not meet the conditions set by the inner join.

Example:

Results:

What do you think of this article on how to achieve connection query in mysql? has it gained anything? If you want to know more about it, you can continue to follow our industry information section.

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