MySQL (11) DQL Joint Query

Source: Internet
Author: User

First, meaning

Union: Merging, combining, merging multiple query results into one result

Second, the grammar

Query Statement 1 Union "all" query Statement 2 Union "all" ...

Third, significance

1. Split a more complex query statement into multiple statements

2, for querying multiple tables, the query column is basically the same

Iv. Features

1. The number of query columns that require multiple query statements must be consistent

2, the query requires multiple query statements of the column type, the order of best consistent

3, Union de-weight, union all contains duplicates

V. Examples

Case 1: Query the department number >90 or the mailbox contains employee information for a

SELECT * FROM Employees WHERE email like '%a% '

UNION

SELECT * FROM Employees WHERE department_id>90;

Case 2: Querying information about men in China and users of middle-aged males in foreign users

SELECT id,cname from T_ca WHERE csex= ' man '

UNION All

SELECT t_id,tname from T_ua WHERE tgender= ' male ';

Vi. Summary of Inquiries

Grammar:

Select query List ⑦

From table 1 alias ①

Connection type join table 2 ②

On connection Condition ③

where filter ④

Group by group List ⑤

Having screening ⑥

Order by sorted list ⑧

Limit Start Entry index, number of entries; ⑨

Follow the public number: Java Back-end life, dry article first time delivery!


MySQL (11) DQL Joint Query

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.