Get the App
SLTechnology News&Howtos  ›  Database  › 

What is a database relational connection

Shulou Source: shulou.com Published: 2022-05-31 17:40:30 10月04日 Update

This article mainly explains "what is a database relational connection". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is a database relational connection"?

Connection classification

Connections between relationships are divided into inner connections (inner join) and external connections (outer join).

External connections can be divided into left outer join,right outer join and full outer join.

Internal connection calculation method:

If no condition is added, it will produce Cartesian product.

If there are join conditions, operate according to the rules of the next section "join conditions", and the tuples that meet the conditions are put into the result relationship.

Left outer join calculation process:

1) calculate the inner join under the same connection condition, and put the qualified tuples into the result relationship.

2) if any tuple in the left relation does not meet the condition, put it in the result relationship and supplement the rest with NULL

Right outer join calculation process:

1) calculate the inner join under the same connection condition, and put the qualified tuples into the result relationship.

2) if any tuple in the right relation does not meet the condition, put it in the result relationship and supplement the rest with NULL

Full outer join

1) calculate the inner join under the same connection condition, and put the qualified tuples into the result relationship.

2) if any tuple in the left-right relationship does not meet the condition, put it into the result relationship, and make up the rest with NULL

As is used to modify the relationship name and attribute name of the result relationship after the connection.

Connection condition

The connection between relationships can be conditional, the outer connection must be conditioned, and the inner connection without conditions will produce Cartesian product.

What are the connection conditions?

Natural--

1) the values of all attributes with the same name in the two relationships (left relationship and friend relationship) should be equal.

2) natural always appears before the join statement

3) in the result relationship of natural, attributes with the same name will only appear once.

4) in the result relation of natural, the order of attributes is always in accordance with the principle of left relation first.

5) in MySQL, natural join cannot use on to specify other query criteria

On--

1) on is used after the join statement

2) relation 1 is adopted after on. Attribute a = relation 2. Predicate syntax for attribute b

Using--

1) similar to natural, except that the attribute name is explicitly specified

2) if using also specifies all attributes with the same name, it is the same as natural

MySQL

In MySQL, natural join and left outer join cannot be used at the same time. You can first make the natural join statement into a view, and then use left outer join

Join defaults to inner join

At this point, I believe you have a deeper understanding of "what is a database relational connection". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Condition result attribute same name data database statement content method process Descartes learning query practical deeper between two interest principle Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn NVidia MariaDB Shulou Information Shulou Technology