Mysql-DQL (joint inquiry)

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:

  1. The number of query column requires a lot of queries is the same!
  2. Type and order of each column requires multiple queries queries of the best consistent
  3. 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';
Published 45 original articles · won praise 43 · views 7075

Guess you like

Origin blog.csdn.net/qq_42193790/article/details/104408000
Recommended