测试必备的Mysql常用sql语句系列
https://www.cnblogs.com/poloyy/category/1683347.html
on
crossjoin ... on
SELECT <字段名> FROM <表1> INNER JOIN <表2> [ON子句]
innerjoin ... on
两张表相连
select * from emp as a inner join dept as b on a.dept_id = b.id;
select * from emp as a join dept as b on a.dept_id = b.id;
可以看到emp表id=7、9的数据是没有返回的,dept表id=4的数据也是没有返回的,这就是inner join的特性:只有两张表相互匹配到的数据才会返回(满足查询条件的数据),简单理解就是:取交集
自连接:同一张表相连
select * from emp as a inner join emp as b on a.leader = b.id;
不等值连接:查询条件的逻辑运算符是大于或小于
select * from emp as a inner join dept as b on a.dept_id > b.id;
表名.字段名
别名.字段名
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有