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