Advanced 9: joint inquiry
union joint merger: the results of multiple queries into a single result of the merger
syntax:
query 1
union
query 2
union
...
Scenario:
The results for the query from multiple tables, multiple tables and there is no direct connection relationship, but when the information is consistent query
Features:
- The number of query column requires a lot of queries is the same!
- Type and order of each column requires multiple queries queries of the best consistent
- union keywords default to heavy, if you use union all may contain duplicates
#案例:查询中国用户中男性的信息以及外国用户中年男性的用户信息
SELECT id,cname FROM t_ca WHERE csex='男'
UNION ALL
SELECT t_id,tname FROM t_ua WHERE tGender='male';