Home > Database > Mysql Tutorial > body text

How does mysql allow tables to establish connections?

little bottle
Release: 2020-09-14 17:45:07
Original
7922 people have browsed it

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 语句]
Copy after login

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;
Copy after login

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;
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template