(11) Federated queries in MySQL

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.