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 are the table join types in SQL Server

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

Share

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

This article will explain in detail what table connection types are available in SQL Server. The quality of the article is high, so Xiaobian shares it with you as a reference. I hope you have a certain understanding of relevant knowledge after reading this article.

Inner join (a typical join operation that uses comparison operators like = or). Includes equal joins and natural joins.

Inner joins use comparison operators to match rows in two tables based on the values of columns common to each table. For example, retrieve all rows in the students and courses tables that have the same student identification number.

2. External connection. An outer join can be a left outward join, a right outward join, or a full outer join.

When you specify an outer join in the FROM clause, it can be specified by one of the following sets of keywords:

LEFT JOIN or LEFT OUTER JOIN

The result set of a left outward join includes all rows of the left table specified in the LEFT OUTER clause, not just rows matched by the join columns. If a row in the left table has no matching row in the right table, all select list columns in the right table in the associated result set row are null.

2) RIGHT JOIN or RIGHT OUTER JOIN

A right outward join is the reverse of a left outward join. All rows of the right table are returned. If a row in the right table has no matching row in the left table, null is returned for the left table.

3) FULL JOIN or FULL OUTER JOIN

A full outer join returns all rows in the left and right tables. When a row has no matching row in another table, the select list column of the other table contains a null value. If there are matching rows between the tables, the entire result set row contains the data values of the base table.

3. Cross connection

The cross join returns all rows in the left table, each row in the left table combined with all rows in the right table. Cross joins are also called Cartesian products.

Examples:

A, table

B, table

Inner connection:

Use inner links in tables A and B to query student names, schools, and occupations

Statement 1: Use the where clause

selcet A.name,A.school,B.name,B.job from A,B where A.name=B.name

Or: Use INNER JOIN... ON clause

select A.name,A,school,B.name,B.job from A inner join B on A.name=B.name

The results are as follows:

External connections:

Left Outside Link:

select A.name,A.school,B.name,B.job from A left join B on A.name=B.name

The results are as follows:

Right outer link: select A.name,A.school,B.name,B.job from A right join B on A.name=B.name The results are as follows:

About SQL Server which table join types are shared here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see 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