MySQL multi-table joint query is a query method of MySQL database. The following describes the syntax of MySQL multi-table joint query for your reference.
MySQL multi-Table Union query syntax:
- SELECT * FROM Insert table left join main table ON t1.lvid = t2.lv _ id
-
- Select * from mytable, title where table name 1. name = table name 2. writer;
-
1. If mysql version is later than 4.0, use UNION for query. The example is as follows:
- SELECT 'id', 'name', 'date', ''as 'type' FROM table_A WHERE condition statement ......
- UNION
- SELECT 'id', 'name', 'date', 'unfinished 'AS 'type' FROM table_ B WHERE condition statement ......
- Order by 'id' LIMIT num;
-
2. If mysql version is earlier than 4.0, you need to create a temporary table in three steps. The example is as follows:
Step 1: create a temporary table tmp_table_name and insert related records in table_A
- $ SQL = "CREATE TEMPORARY TABLE tmp_table_name SELECT 'id', 'name', 'date', 'complete the 'as 'type' FROM table_A WHERE Condition Statement ......";
- Mysql_query ($ SQL) OR die ("query false !");
Step 2: obtain related records from table_ B and insert them to the temporary table tmp_table_name.
- Mysql_query ("insert into tmp_table_name SELECT 'id', 'name', 'date2' AS 'date', 'unfinished 'as 'type' FROM table_ B WHERE Condition Statement ......") OR die ("query false !");
Step 3: retrieve records from the temporary table tmp_table_name
- mysql_query(”SELECT * FROM tmp_table_name ORDER BY id DESC”) or die (”query false!”);
Alternative usage of MySQL table alias
MySQL left join query Experience Summary
How to display MYSQL table information
Three Common MySQL table creation statements
MySQL connection Query