Federated Queries
Union query : concatenation of multiple queries (multiple SELECT statements) on records (fields do not increase)Basic Syntax:Multiple SELECT statements, the number of fields that each SELECT statement obtains must be strictly consistent (but field data type independent)SELECT statement 1,Union [Union option]SELECT statement 2 ...Union options: All: Reserved, Distinct: Repeat (default)
Meaning:1. Query the same table, but the requirements are different, for example: Query student information, Boys age ascending, girls age descending2. Multi-table query, the structure of multiple tables is exactly the same as the data savedHow to achieve the student table in the height of the boys ascending, the girls rise descending?use of Order by in a federated query1, the order by cannot be used directly in a federated query, you need to use parentheses for the query statement.2, if the order by is valid, you must use the maximum number of limits with limit limiteg:(SELECT * from student where sex = ' man ' ORDER by age ASC limit 999999)Union(SELECT * from student where sex = ' woman ' ORDER BY age desc limit 999999);
(11) Federated queries in MySQL