SQL语言总结——多表查询

多表查询

一、sql92格式

  • 内连接

    *等值连接: where table1.key = table2.id

    *非等值连接: where table1.salary between t2.low and t2.high;//不再是等于判断

    *自连接 : where t1.managerId = t1.id;//在一个表中连接两个字段

二、sql99格式

语法格式:select 查询列表 from 表1 别名 **【连接类型】 join 表2 别名 on 连接条件** 【where条件...】

内连接仅显示两表匹配数据,外连接 = 内连接 + 未匹配NULL数据,左外连接以左表为主,右连接以右表为主

  • 内连接inner

    *等值连接: inner join table2 on table1.key = table2.id

    *非等值连接: inner join t2 on t1.salary between t2.low and t2.high;//不再是等于判断

    *自连接: inner join t1 on t1.managerId = t1.id;//在一个表中连接两个字段

  • 外连接outer

    *左外连接left outer select * from t1 left join t2 on t1.id = t2.UID;

    *右外连接right outer select * from t1 right join t2 on t1.id = t2.UID;

  • 交叉连接cross select * from t1 right join t2;//笛卡尔乘积结果

为表起别名,可以提高语句的简介度,关键词as可以省略

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值