mysql多表连接查询union,cross join,inner join,nature join

union联合查询select * from 表 union select * from 表;

union语句必须有两条或两条以上的select组成并且具有相同的列,表达式,聚合函数

每个Select 语句中对应的目标列数据必须兼容

第一个select语句中的列名称会作为union结果集的列名称

只能使用一次 order by 和limit并放在最后一句select 后

select * from 表 union all select * from 表 order by 字段(数字) asc limit 2,3;

union all 不去重select * from 表 union all select * from a;

多表连接查询

笛卡尔积

cross join select * from 表 cross join 表;

或select * from 表1,表2;

内连接 inner join select * from 表1 inner join 表2 where 表1.字段=表2.字段;

或select * from 表1 inner join 表2 on 表1.字段=表2.字段;w

或select * from 表1,表2 where 表1.字段=表2.字段

自然连接当想连接的两个表中有相同的字段时使用

nature join

左外连接 left join select * from 表名 left join 连接表 on 表.字段=连接表.字段 以左表为主如过左表字段有空值那么用null补齐

右外连接 right join select * from 表名 right join 连接表 on 表.字段 = 连接表.字段; 以右表为主

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值