2022-10-31
閱讀量:
546
mysql學(xué)習(xí)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重復(fù)的記錄,有重復(fù)值后, 分別用union all連接與union 連接,對比一下結(jié)果
insert into q1 values('a',1),('a',2),('b',3),('c',4),('a',13);
-- 看一下 union縱向連接的結(jié)果
select * from t1
union
select * from q1;
-- 看一下 union all縱向連接的結(jié)果
select * from t1
union all
select * from q1;
# 發(fā)現(xiàn):union 自動去重, union all 不去重






評論(0)


暫無數(shù)據(jù)
推薦帖子
0條評論
1條評論
0條評論