联合查询

union 联合 合并:将多条查询语句的结果合成一个结果

特点:

1.要求多条查询语句的列数一致

2.要求多条查询语句的查询的每一列的类型和顺序最好一致

3.union关键词默认去重,用union all则不去重

语法:

查询语句1

union

查询语句2

......

#案例:查询中国用户男性以及外国用户中年龄>12岁的用户信息

select id,name,csex from y_ca where sex = '男'

union

select t_id,tname,tgender from t_ua where tgender = 'male' ;

posted @ 2022-12-15 20:00  平凡的柳先生  阅读(46)  评论(0)    收藏  举报