There are many ways to write multi-table SQL statements in MySql. This article will explain and use multi-table query statements.
Recommended course: MySQL tutorial
##In SQL language, there are two ways Specify an alias for the table
The first is to specify it through the keyword AS,The second is to add the alias of the table directly after the table name
You should pay attention to a few points when using the alias of the table
(1) An alias is usually a shortened table name, used to refer to a specific column in a table in a connection. If there are columns with the same name in multiple tables in the connection, the table name or table name must be used. Alias qualified column name
(2) If the alias of the table is defined, the table name cannot be used
1. Use the SELECT clause for multi-table query
SELECT field name FROM Table 1, Table 2... WHERE Table 1. Field = Table 2. Field AND other query conditions Example:SELECT a.id,a.name,a.address,a.date,b.math,b.english,b.chinese FROM tb_1 AS b,tb_2 AS a WHERE a.id=b.id
2. Use table aliases to perform multiple Table query
Example:SELECT a.id,a.name,a.address,b.math,b.english,b.chinese FROM tb_1 a,tb_2 b WHERE a.id=b.id AND b.id='$_POST[textid]'
The above is the detailed content of How to connect multiple tables in MySQL using sql statements. For more information, please follow other related articles on the PHP Chinese website!