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

The method of joining SQL Table

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

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "the method of SQL table join". In the daily operation, I believe that many people have doubts about the method of SQL table join. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "SQL table join method". Next, please follow the editor to study!

You can see it through the picture.

Multi-table queries are divided into inner and outer joins.

External connections are divided into left connections (left join or left outer join), right connections (right join or right outer join), and complete external connections (full join or full outer join)

The result of a left join (left join or left outer join) is all rows of the left table in the left join clause, not just the rows matched by the link column. If a row in the left table does not match in the right table, all selected columns of the right table in the associated result row are null (NULL)

SQL syntax select * from table1 left join table2 on table1. Conditional column name = table2. Conditional column name

Note: all the columns in table1 and the columns that can match are displayed

The right link (right join or right outer join) doesn't say much here. The left link is very similar but vice versa. Just say the grammar.

Select * from table1 right join table2 on table1. Condition column = table2. Conditional column

Full external connection (full join or full outer join)

Displays all rows in the left and right table. When there are no matching rows in one table, the select list column of the other table contains null values (NULL). If so, all data is displayed.

SQL syntax:

Select * from table1 full join table2 on table1. Conditional column name = table2. Conditional column name

Internal connection:

Concept: an inner join is a connection that uses a comparison operator to compare the values of a join column.

Internal connection (join or inner join)

SQL syntax:

Select * fron table1 join table2 on table1. Conditional column name = table2. Conditional column name

Returns two table columns that meet the matching criteria

Equivalent to:

Select A *, B * from table1 A, table2 B where A. Condition column name = B. Conditional column name

Select * form table1 cross join table2 where table1. Conditional column name = table2. Conditional column name (Note: Cross join cannot be followed by on but where)

Cross-connect (full)

Concept: the number of rows of the first table multiplied by the number of rows of the second table is equal to the Cartesian product and the size of the result set without a cross join with the where clause

Cross-connect: Cross join (without conditional where, if returned or displayed is the number of matching rows)

SQL syntax:

Select * from table1 cross join table2

If there are conditions (where)

Select * from table1 cross join table2 where table1. Conditional column name = table2. Conditional column name

Equivalent to

Select * from table1,table2 (without where)

At this point, the study of "the method of SQL table join" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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