当前位置:网站首页>多表操作-外连接查询
多表操作-外连接查询
2022-07-04 18:32:00 【汤键.TJ】
目录
- 外连接查询分为左外连接查询和右外连接查询
- 以某张表为主,取出里面的所有记录,然后每条与另外一张表进行连接,不管能不能匹配上条件,最终都会保留
- 能匹配,正确保留;不能匹配,其它表的字段都置空(null),称为外连接
左外连接
- 查询原理
- 查询左表的全部数据,和左右两张表有交集部分的数据
- 查询语法
- select 列名 from 表名1 left [outer] join 表名2 on 条件
右外连接
- 查询原理
- 查询右表的全部数据,和左右两张表有交集部分的数据
- 查询语法
- select 列名 from 表名1 right [outer] join 表名2 on 条件
实例操作
- 表的数据准备请点击查看
- 左外连接
- 查询所有用户信息,以及用户对应的订单信息
-- 左外连接 -- 查询所有用户信息,以及用户对应的订单信息 SELECT u.*, o.number FROM user u LEFT OUTER JOIN orderlist o ON o.uid=u.id;
- 右外连接
- 查询所有订单信息,以及订单所属的用户信息
-- 右外连接 -- 查询所有订单信息,以及订单所属的用户信息 SELECT o.*, u.name FROM user u RIGHT OUTER JOIN orderlist o ON o.uid=u.id;
边栏推荐
猜你喜欢
YOLOv5s-ShuffleNetV2
Introduction to polyfit software
与二值化阈值处理相关的OpenCV函数、方法汇总,便于对比和拿来使用
Oracle with as ora-00903: invalid table name multi report error
“只跑一趟”,小区装维任务主动推荐探索
Bi skills - permission axis
92. (cesium chapter) cesium building layering
mysql中explain语句查询sql是否走索引,extra中的几种类型整理汇总
FPGA时序约束分享01_四大步骤简述
Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading
随机推荐
Personal thoughts on Architecture Design (this article will be revised and updated continuously later)
kotlin 条件控制
牛客小白月赛7 谁是神箭手
Several methods of online database migration
1003 Emergency(25 分)(PAT甲级)
The difference and usage between substr (), slice (), and substring () in the string interception methods of "understand series after reading"
测试工程师如何“攻城”(下)
Stream流
HDU 1372 & POJ 2243 Knight moves (breadth first search)
OpenCV的二值化处理函数threshold()详解
Allure of pytest visual test report
1006 Sign In and Sign Out(25 分)(PAT甲级)
Pytorch学习(四)
The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
偏移量函数及开窗函数
1007 maximum subsequence sum (25 points) (PAT class a)
Reflection (I)
线上数据库迁移的几种方法
Lenovo explains in detail the green smart city digital twin platform for the first time to solve the difficulties of urban dual carbon upgrading