The following editor will bring you a brief discussion on the implementation method of ##mysqlmulti-table non-correlatedquery. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.
When you useMySQL to query, it is usually a direct query of one table, or it is a related query of multiple tables. Left join (left join), right join (right join), inner join (inner join), and outer join (outer join) are used. This kind of relationship has a certain relationship between the two tables, which is what we often say has a foreign key corresponding relationship, which can be written using the statement a.id = b.aId. This is commonly used by everyone, but sometimes we need to query two or more tables at the same time, and these tables are not related to each other. For example, if we want to query certain data in the user table and user_history table, This time is the so-called non-correlated query.
Theunion all statement is used at this time. For example:
(select name,sex,age from user where name like '王%' ) union all (select name,sex,age from user_history where name like '王%' ) ;
(select name,sex,age from user where name like '王%' ) union all (select name,sex,age from user_history where name like '王%' ) order by age desc limit 0,50;
The above is the detailed content of Detailed explanation of the implementation method of multi-table non-correlated query in mysql. For more information, please follow other related articles on the PHP Chinese website!