Database 1 relational (relation) tuple (tuple) join__ database

Source: Internet
Author: User
Tags joins one table

A relational model is a table-based model in which a table with columns (attributes) and data can be considered as a relationship relational algebraic set, and a repeating tuple is always excluded. such as union and union all, for the returned query results, the former will be random deletion of duplicates a lookup and ordering are unstable, different operating systems for the same insert tuple data will have different sorting data Automatic conversion of data types in other advanced languages is still valid, such as float and int,100.0 float. Can I force type conversions ... OK. Include explicit and implicit, see: SQL type conversion SQL statements are designed in the most efficient way, although the query logic is more troublesome than Java C : The combination of the relationship name and its property set is called a schema schema, for example

Table Name (property 1, Property 2 ...)

In MySQL, databases and schemas are the same, such as typing in MySQL: Show schemas, which returns the same result as show databases;
The result of Create schema SH1 and create database SH2 is the same;
There is no concept of catalog in MySQL, and there is no syntax for create catalog ; a database has one or more relationships, and the relational collection pattern of the database is called the database schema. tuples: In a relationship, a row other than the row containing the property name is called a tuple (tuple) as

Relationship instance: a set of tuples in a given relationship relationship constraint: key. no two tuples have the same value on all the properties that make up the key, although they may have the same value on some of the properties that make up the key. projection: Generating a new relationship from the original relationship, containing a partial column of the original relationship selection: Subset of the tuple of the original relationship commonly said join is a cross join (cross join), that is, the Cartesian product A natural connection (natural join): A special equivalent connection that automatically matches a column with the same name in a table, automatically determines the column of the same name, and then forms a match. The disadvantage is that although you can specify which columns the query results include, you cannot artificially specify which columns are matched. Natural connections do not have to specify any equivalent join conditions. There is only one matching column in the resulting table after the connection. Tuples that do not have common attributes are ignored, known as the levitation progenitor
A B C
1 2 3
6 7 8
9 7 8

+

B C D
2 3 4
2 3 5
7 8 10

=

A B C D
1 2 3 4
1 2 3 5
6 7 8 10
9 7 8 10

Use natural joins to note that two tables with the same name cannot have more than 1 columns.
Natural join: Indicates a natural connection between two tables, and the connection is based on all the same name segments in both tables.
Join...using: For two tables with the same name, but the data type is different, or use more than one of the same name to do an equivalent connection
Join...on: The most flexible, can indicate the conditions of the connection.

Select *from test_table_a join Test_table_b using (name);  

=

Select *from test_table_a, Test_table_b where a.name=b.name;  

Natural joins using the natural join operator are equivalent to examining where clauses that are equal to the same name in the two source tables : connections are divided into conditional connections, equivalent connections and natural connections of three species.

1. A conditional connection is a connection that selects rows that satisfy a condition in the Cartesian product of multiple tables, such as a conditional query such as SELECT * from A,b where A.A > a.b.

2, the equivalent connection is a special condition connection, when the condition is a field = a field, that is the equivalent connection. such as select Ename,sal,dname from emp,dept where Emp.deptno=dept.deptno;

3, natural connection is a special equivalent connection, he asked that more than one table has the same property field, then the condition is the same property field values are equal, and finally the table repeated the property field removed, that is, the natural connection. The SELECT * from A natural join B is equivalent to select a.a,a.b,a.c,b.d from A.C = B.C, as in the A,b,c field in a and the C,d field in B. the difference between an inner connection and an equivalent connection: Inner joins: A connection in which a data item is equal in two tables (or connections) is called an inner join. The equivalent connection generally sets the condition in the WHERE clause, the inner join generally sets the condition with the ON clause, but the inner join and the equivalent connection effect are the same. Inner joins are essentially the same as natural connections, except that a natural connection can only be an equivalent connection to an attribute of the same name, whereas an inner join may use a using or ON clause to specify the join condition, which indicates that a two field is equal (you can have different names).

The inner connection and the equivalent connection are actually one thing (equivalent).

It is often asked to select A.id,b.name from A,b where A.id=b.pid and

What is the difference between select A.id,b.name from a inner join B on a.id=b.pid, and which is more efficient.

Actually one thing at a time. Only the inner joins are written in the SQL 1999 rule. The two are talking about the same.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.