2022-10-31
阅读量:
510
mysql学习14-纵向合并查询
-- 25 纵向合并查询
-- union去重
create table q1(sname char,sid int);
create table q2(sname char,score int);
insert into q1 values('m',1),('n',2),('r',3),('f',4),('g',13);
insert into q2 values('m',78),('n',78),('r',56),('f',73),('g',64);
#将t1与q1纵向合并
select * from t1
union
select * from q1;
#给q1输入一些与t1重复的记录,有重复值后, 分别用union all连接与union 连接,对比一下结果
insert into q1 values('a',1),('a',2),('b',3),('c',4),('a',13);
-- 看一下 union纵向连接的结果
select * from t1
union
select * from q1;
-- 看一下 union all纵向连接的结果
select * from t1
union all
select * from q1;
# 发现:union 自动去重, union all 不去重






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论