MySQL笔记 联合查询union
语法:
查询语句1
union
查询你语句2
应用场景:
要查询的结果来自多个表,且多个表没有直接的连接关系,但查询的信息一致时
特点:
-
要求多条查询语句的查询列数是一致的
-
要求多条查询语句的查询的每一列的类型和顺序最好一致
-
union关键字默认去重,如果使用union all可以包含重复项
案例:
查询中国用户中男性的信息以及外国用户中男性的用户信息
select id, name from t_ca where csex='男' union select t_id, tName from t_ua where tGender='male';