MYSQL 连接举例

内连接:连接的多个数据必须存在才能连接
select * from sjh1
4482条记录

create table sjha as ( select * from sjh1 limit 20 )
select * from sjha
20条记录

根据sjh1表的前20条记录新建表sjha
内连接 左连接 右连接
select * from sjha,sjh1 where sjha.sjh=sjh1.sjh
按条件连接
select * from sjha join sjh1 on sjha.sjh=sjh1.sjh
select * from sjha inner join sjh1 on sjha.sjh=sjh1.sjh
内连接
select * from sjha left join sjh1 on sjha.sjh=sjh1.sjh
左连接
显示20条

select * from sjha right join sjh1 on sjha.sjh=sjh1.sjh
右连接
显示4482条,左边大部分为null
union 全连接

select * from sjha union select * from sjh1
4482
(select * from sjha order by rq) union (select * from sjh1 order by sjh1.rq)
4482 没排序
(select * from sjha ) union (select * from sjh1 ) order by rq
4482 排序

select * from sjha union all select * from sjh1
4502
(select * from sjha order by rq) union all (select * from sjh1 order by sjh1.rq)
4502 没排序

(select * from sjha ) union all (select * from sjh1 ) order by rq
4502 排序

 

posted @ 2021-01-13 15:17  myrj  阅读(75)  评论(0编辑  收藏  举报