Home > Database > Mysql Tutorial > body text

How to query two tables in mysql

青灯夜游
Release: 2021-12-07 10:51:01
Original
20994 people have browsed it

Methods to query two tables: 1. Use the SELECT statement and the "CROSS JOIN" keyword to perform cross-join queries; 2. Use the SELECT statement and the "INNER JOIN" keyword to perform inner join queries; 3. Use SELECT statement and "OUTER JOIN" keyword perform outer join query.

How to query two tables in mysql

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

In a relational database, tables are related, so in practical applications, multi-table queries are often used. Multi-table query is to query two or more tables at the same time.

In MySQL, multi-table queries mainly include cross joins, inner joins and outer joins.

MySQL Cross Join

Cross join (CROSS JOIN) is generally used to return the Cartesian product of the joined table.

The syntax format of cross-connection is as follows:

SELECT <字段名> FROM <表1> CROSS JOIN <表2> [WHERE子句]
Copy after login

or

SELECT <字段名> FROM <表1>, <表2> [WHERE子句]
Copy after login

The syntax description is as follows: