Home  >  Article  >  Database  >  How does mysql allow tables to establish connections?

How does mysql allow tables to establish connections?

little bottle
little bottleOriginal
2019-05-13 14:56:157806browse

In order to reduce the limited storage space occupied by data, relational databases will perform standardization processing by dividing data into several tables. Reuniting the data managed by these divisions is table connection processing. The following will introduce how mysql allows tables to establish connections.

How does mysql allow tables to establish connections?

1. Inner join

Inner join is to connect the primary key and foreign key between tables, and only obtain the data with the same key value connection method.

Specific syntax:

Select 列名1…from 表1 inner join 表2 on 表1.外键=表2.主键 [where /order by 语句]

For example:

Create a class database and two tables, student and goods, and corresponding fields, where student is the main table and its foreign key goodsID corresponds to the primary key id of the goods table, query statement (record the table name student as s, goods as g for easy reference)

select s.name,s.phonenumber,g.name from student as s inner join goods as g on s.goodsID=g.ID;

2. Inner join of multiple tables

The following connects the data of the four tables by setting foreign keys.

select s.name,s.phonenumber,s.sex,g.name,c.classname,a.address from ((student as s inner join goods as g on s.goodsID=g.ID)inner join classname as c on s.ID=c.ID)inner join address as a on c.ID=a.ID;

The above is the detailed content of How does mysql allow tables to establish connections?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn