MySQL join table, mysql join

Source: Internet
Author: User

MySQL join table, mysql join
One of the most powerful functions of join SQL is to join tables in the execution of data search and query. Joined tables are based on Relational Tables. The following table lists the relationships. If multiple items produced by the same supplier need to store product information in the database, the supplier information is not stored in the product information line, because the suppliers of these products are the same, you can record a unique supplier id in the product information line. The supplier information is stored in a separate table, it is also used as an id record. In this way, the product table and supplier table are connected by the Common Supplier id. See the following table:


In the vendors table, vend_id is called a primary key, and vend_id in the products table is a foreign key.
Why join tables? Breaking data into multiple tables can be stored more efficiently, processed more conveniently, and scalable. However, these benefits come at a cost. If the data is stored in multiple tables, how can we use a single SELECT statement to retrieve the data? The answer is to use connections. In short, join is a mechanism used to join a table in a SELECT statement. Therefore, join is called join.
The most important part of the following example is vendors. vend_id = products. vend_id. During the comparison, each row is taken out from the vendors table one by one. Each row is compared with all rows in the products table, and each row that meets the conditions in the products table is filtered out.


In addition, the JOIN table can also be expressed using inner join... ON. The function of the statement is the same as that in the preceding example:


Join multiple tables. We can understand the three conditions of WHERE in the following example. The first condition indicates that each product in the product table has a vend_id, and some products are not filtered out; the second condition is that the product on the order should be part of all products. The third condition is the product with the order number 20005;


Mysql query 3 Table connection Query

Select A. c1, B. c1, C. c1 from A left join B on A. c2 = B. c2 left join C on A. c3 = C. c3 where...

How does a table join operation in mysql work?

The Cartesian Product Operation in the set operation is filtered Based on the join conditions.

Related Article

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.