mysql表合并_mysql表的连接语句(包括纵向合并)⽤到的表: t1 t2
t1表
t2表
mysql下载链接
1 -- 左连接
select * from t1 left join t2 on key1 = key2;
2 -- 左连接 , t1-t2
select * from t1 left join t2 on key1 = key2
where key2 is null;
3 -- 右连接
select * from t1 right join t2 on key1 = key2;
4 -- 右连接 t2-t1
select * from t1 right join t2 on key1 = key2
where t1 is null;
5 -- 内连接
select * from t1 inner join t2 on key1 = key2;
6 -- 全连
select * from t1 full outer join t2 on key1 = key2;
7 -- t1+t2 - t1&t2
select * from t1 full outer join t2 on key1 = key2 where key1 is null or key2 is null;
8 -- 纵向合并 union 合并后删除重复值
select * from t1
union
select * from t2;
9 -- 纵向合并 union all 合并后保留重复值
select * from t1
union all
select * from t2;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。