当前位置:网站首页>【mysql学习笔记19】多表查询
【mysql学习笔记19】多表查询
2022-06-21 16:02:00 【yqs_281876918】
笛卡尔积查询
select * from emp,dept;
相当于对emp表和dept做了笛卡尔积操作
简单多表查询
select * from emp,dept where emp.dept_id=dept.id;
相当于查询员工的部门信息
内连接
语法1:select * from emp inner join dept on emp.dept_id=dept.id;
语法2:select * from emp,dept where emp.dept_id=dept.id;
两者效果是一样的
左连接、右连接、内连接综合练习
表结构

select * from emp,dept where emp.dept_id=dept.id-1 or emp.dept_id=dept.id;
select * from emp left join dept on emp.dept_id=dept.id-1 or emp.dept_id=dept.id;
select * from emp right join dept on emp.dept_id=dept.id;
结果展示(按sql语句顺序)


说明
左连接就是把左表中没有出现过的记录拿出来,然后在剩余的字段中全填null。
右连接同理。
自连接
select 字段列表 from 表A 别名A join 表B 别名B on 条件;
select 字段列表 from 表A 别名A left join 表B 别名B on 条件;
select 字段列表 from 表A 别名A right join 表B 别名B on 条件;
边栏推荐
- Fidder工具使用笔记
- The beta version of move protocol is stable, and it is temporarily decided to expand the scale of the prize pool
- Esp8266/esp32 get NTP time method through timelib Library
- Do Internet companies do unit tests? Is it necessary to do unit testing for the needs of the bank?
- Online shopping website (final assignment)
- Research on symmetric TSP Based on MATLAB
- 机器学习模型监控(Aporia)
- Reinforcement learning introductory project spinning up (1) installation
- 剑指 Offer II 089. 房屋偷盗 / 剑指 Offer II 090. 环形房屋偷盗
- Set up your own website (11)
猜你喜欢
随机推荐
使用unittest框架生成测试报告
网购网站(期末大作业)
【SQLite】解决unrecognized token:“‘“
Pytest框架实现前后置的处理
Garbage collector
撰写有效帮助文档的7大秘诀
新增Razor组件支持代理连接RDP,JumpServer堡垒机v2.23.0发布
Elegant request retry using guzzle Middleware
Beaucoup de sociétés de logiciels sont en fait des "blagues"
AutoK3s v0.5.0 发布 延续简约和友好
Postman basic operations
Why do you want to develop tea mall applet app?
Fisher信息量检测对抗样本代码详解
How to open an account for futures agricultural products? How much is the handling charge?
Interface automatic encryption and decryption
Fidder工具使用笔记
【1108. IP 地址无效化】
Undefined functions or variables [explained in one article] (matlab)
d改进翻译
Online JSON to yaml tool









