Database_10_joint query

#Advanced9: Joint query

union: Combine the results of multiple query statements into one result

Syntax:
query statement 1
union
query statement 2
union

Application scenario: When
the results to be queried come from multiple tables, and multiple tables have no direct connection relationship, but the query information is consistent

Features:
1. The number of query columns of
multiple query statements is required to be consistent . 2. The data type of each column of multiple query statements is required to be consistent . 3.
Union defaults to de-duplication. If union all is used, duplicate items can be included.

#----------------------------------------------
#Case 1 :Query department number "90 or the mailbox contains employee information of a

SELECT * FROM employees
WHERE department_id>90
UNION 
SELECT * FROM employees
WHERE email LIKE '%a%';

#Case 2: Query information about males among Chinese users and information about males among foreign users

SELECT id,cname,csex FROM t_ca WHERE csex='男'
UNION 
SELECT t_id,tName,t_Gender FROM t_ua WHERE tGender='male';

Guess you like

Origin blog.csdn.net/Yungang_Young/article/details/104732026