two articles about MySQL - LEFT JOIN and RIGHT JOIN, INNER JOIN and OUTER JOIN

PT静态时序分析实战:从基础命令到高级报告解析 本文详细介绍了PT(PrimeTime)静态时序分析(STA)的实战技巧,从基础命令如pt_shell和report_timing的使用,到高级报告解析与问题排查。通过丰富的实例和脚本示例,帮助工程师快速掌握时序分析的核心技能,提升芯片设计验证效率。 阅读详情
The Horse's Mouth
MySQL - LEFT JOIN and RIGHT JOIN, INNER JOIN and OUTER JOIN
In a database such as MySQL, data is divided into a series of tables (the "why" is beyond what I'm writing today) which are then connected together in SELECT commands to generate the output required. I find when I'm running MySQL training, people often get confused between all the join flavours. Let me give you an example to see how it works.

If this isn't quite the question you're looking to have answered, we've got a MySQL IAQ (Infrequently Answered Questions that may help you

First, some sample data:
Mr Brown, Person number 1, has a phone number 01225 708225
Miss Smith, Person number 2, has a phone number 01225 899360
Mr Pullen, Person number 3, has a phone number 01380 724040
and also:
Person number 1 is selling property number 1 - Old House Farm
Person number 3 is selling property number 2 - The Willows
Person number 3 is (also) selling property number 3 - Tall Trees
Person number 3 is (also) selling property number 4 - The Melksham Florist
Person number 4 is selling property number 5 - Dun Roamin.


mysql> select * from demo_people;
+------------+--------------+------+
| name | phone | pid |
+------------+--------------+------+
| Mr Brown | 01225 708225 | 1 |
| Miss Smith | 01225 899360 | 2 |
| Mr Pullen | 01380 724040 | 3 |
+------------+--------------+------+
3 rows in set (0.00 sec)

mysql> select * from demo_property;
+------+------+----------------------+
| pid | spid | selling |
+------+------+----------------------+
| 1 | 1 | Old House Farm |
| 3 | 2 | The Willows |
| 3 | 3 | Tall Trees |
| 3 | 4 | The Melksham Florist |
| 4 | 5 | Dun Roamin |
+------+------+----------------------+
5 rows in set (0.00 sec)

mysql>


If I do a regular JOIN (with none of the keywords INNER, OUTER, LEFT or RIGHT), then I get all records that match in the appropriate way in the two tables, and records in both incoming tables that do not match are not reported:


mysql> select name, phone, selling
from demo_people join demo_property
on demo_people.pid = demo_property.pid;
+-----------+--------------+----------------------+
| name | phone | selling |
+-----------+--------------+----------------------+
| Mr Brown | 01225 708225 | Old House Farm |
| Mr Pullen | 01380 724040 | The Willows |
| Mr Pullen | 01380 724040 | Tall Trees |
| Mr Pullen | 01380 724040 | The Melksham Florist |
+-----------+--------------+----------------------+
4 rows in set (0.01 sec)

mysql>


If I do a LEFT JOIN, I get all records that match in the same way and IN ADDITION I get an extra record for each unmatched record in the left table of the join - thus ensuring (in my example) that every PERSON gets a mention:


mysql> select name, phone, selling
from demo_people left join demo_property
on demo_people.pid = demo_property.pid;
+------------+--------------+----------------------+
| name | phone | selling |
+------------+--------------+----------------------+
| Mr Brown | 01225 708225 | Old House Farm |
| Miss Smith | 01225 899360 | NULL |
| Mr Pullen | 01380 724040 | The Willows |
| Mr Pullen | 01380 724040 | Tall Trees |
| Mr Pullen | 01380 724040 | The Melksham Florist |
+------------+--------------+----------------------+
5 rows in set (0.00 sec)

mysql>


If I do a RIGHT JOIN, I get all the records that match and IN ADDITION I get an extra record for each unmatched record in the right table of the join - im my example, that means that each property gets a mention even if we don't have seller details:


mysql> select name, phone, selling
from demo_people right join demo_property
on demo_people.pid = demo_property.pid;
+-----------+--------------+----------------------+
| name | phone | selling |
+-----------+--------------+----------------------+
| Mr Brown | 01225 708225 | Old House Farm |
| Mr Pullen | 01380 724040 | The Willows |
| Mr Pullen | 01380 724040 | Tall Trees |
| Mr Pullen | 01380 724040 | The Melksham Florist |
| NULL | NULL | Dun Roamin |
+-----------+--------------+----------------------+
5 rows in set (0.00 sec)

mysql>


An INNER JOIN does a full join, just like the first example, and the word OUTER may be added after the word LEFT or RIGHT in the last two examples - it's provided for ODBC compatability and doesn't add an extra capabilities.

Extra link to three way join in solution centre (would have added that link in the comment except that it "spam trapped! 
下面这个简单的教程来自 www.w3schools.com这个网站,很不错的网站!

SQL JOIN

previous next

Joins and Keys

Sometimes we have to select data from two or more tables to make our result complete. We have to perform a join.

Tables in a database can be related to each other with keys. A primary key is a column with a unique value for each row. Each primary key value must be unique within the table. The purpose is to bind data together, across tables, without repeating all of the data in every table.

In the "Employees" table below, the "Employee_ID" column is the primary key, meaning that no two rows can have the same Employee_ID. The Employee_ID distinguishes two persons even if they have the same name.

When you look at the example tables below, notice that: 

  • The "Employee_ID" column is the primary key of the "Employees" table
  • The "Prod_ID" column is the primary key of the "Orders" table
  • The "Employee_ID" column in the "Orders" table is used to refer to the persons in the "Employees" table without using their names

Employees:

Employee_IDName
01Hansen, Ola
02Svendson, Tove
03Svendson, Stephen
04Pettersen, Kari

Orders:

Prod_IDProductEmployee_ID
234Printer01
657Table03
865Chair03


Referring to Two Tables

We can select data from two tables by referring to two tables, like this:

Example

Who has ordered a product, and what did they order?

SELECT Employees.Name, Orders.Product
FROM Employees, Orders
WHERE Employees.Employee_ID=Orders.Employee_ID

Result

NameProduct
Hansen, OlaPrinter
Svendson, StephenTable
Svendson, StephenChair

Example

Who ordered a printer?

SELECT Employees.Name
FROM Employees, Orders
WHERE Employees.Employee_ID=Orders.Employee_ID
AND Orders.Product='Printer'

Result

Name
Hansen, Ola


Using Joins

OR we can select data from two tables with the JOIN keyword, like this:

Example INNER JOIN

Syntax

SELECT field1, field2, field3
FROM first_table
INNER JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield

Who has ordered a product, and what did they order?

SELECT Employees.Name, Orders.Product
FROM Employees
INNER JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID

The INNER JOIN returns all rows from both tables where there is a match. If there are rows in Employees that do not have matches in Orders, those rows will not be listed.

Result

NameProduct
Hansen, OlaPrinter
Svendson, StephenTable
Svendson, StephenChair

Example LEFT JOIN

Syntax

SELECT field1, field2, field3
FROM first_table
LEFT JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield

List all employees, and their orders - if any.

SELECT Employees.Name, Orders.Product
FROM Employees
LEFT JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID

The LEFT JOIN returns all the rows from the first table (Employees), even if there are no matches in the second table (Orders). If there are rows in Employees that do not have matches in Orders, those rows also will be listed.

Result

NameProduct
Hansen, OlaPrinter
Svendson, Tove 
Svendson, StephenTable
Svendson, StephenChair
Pettersen, Kari 

Example RIGHT JOIN

Syntax

SELECT field1, field2, field3
FROM first_table
RIGHT JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield

List all orders, and who has ordered - if any.

SELECT Employees.Name, Orders.Product
FROM Employees
RIGHT JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID

The RIGHT JOIN returns all the rows from the second table (Orders), even if there are no matches in the first table (Employees). If there had been any rows in Orders that did not have matches in Employees, those rows also would have been listed.

Result

NameProduct
Hansen, OlaPrinter
Svendson, StephenTable
Svendson, StephenChair

Example

Who ordered a printer?

SELECT Employees.Name
FROM Employees
INNER JOIN Orders
ON Employees.Employee_ID=Orders.Employee_ID
WHERE Orders.Product = 'Printer'

Result

Name
Hansen, Ola
蓝牙模块HM-10手册 蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。 立即下载

相关推荐

CCC数字钥匙3.0标准解读(16)

介绍通信过程最重要部分:身份认证和加密.介绍需要身份认证的过程和需要加密的数据及过程.

weixin_41738640的博客 1545

SQL语句子查询:in,left join,right join,all,any,some

in子查询: 外连接:分为左外连接和右外连接 左外连接: 右外连接: 三表联结查询: any,some,all的用法:

正在改bug的博客 1080

NVIDIA DGX Spark 深度应用解析:从大模型训练到边缘推理的完整实践指南

内存管理:充分利用统一内存架构,避免不必要的数据传输批处理大小:根据模型大小调整批处理大小以优化内存使用精度选择:在精度损失可接受范围内使用较低精度计算流水线优化:重叠计算和数据传输操作DGX Spark作为一个专门的AI计算平台,在大模型开发的各个阶段都能发挥重要作用。从数据预处理到模型训练,从微调到推理部署,其统一内存架构和强大的计算能力为AI开发者提供了前所未有的本地开发体验。需要注意的是,虽然DGX Spark性能强大,但合理的算法设计和系统优化仍然是获得最佳性能的关键。

time_days的博客 2879

php access left join,LEFT JOIN 和 RIGHT JOIN 运算 (Microsoft Access SQL)

LEFT JOIN 和 RIGHT JOIN 运算 (Microsoft Access SQL)LEFT JOIN, RIGHT JOIN Operations (Microsoft Access SQL)09/18/2015本文内容适用于:Access 2013、Office 2013Applies to: Access 2013, Office 2013在任何 FROM 子句中用于组合源表记录...

weixin_39853131的博客 256

antv x6 沿边图标循环动画实现

2.使用transition给边设置动画,利用complte方法实现循环动画。实现效果,如下图,边上存在两个图标,要求图标延边一直循环动画。1.注册一个自定义边,边上定义两个图标,并设置其初始位置。

lingliu0824的博客 3370

文华财经公式编程:麦语言简介及基础语法

文华财经公式语言(麦语言)是一种专门用于金融领域的编程语言,它是由文华财经公司开发的。提供了丰富的金融计算函数和数据处理功能,可以用于金融市场的数据分析、模型建立和交易策略的开发。例1:A:CLOSE;// 定义变量A为收盘价(盘中k线没有走完的时候A为最新价)。例2:MA5:=MA(C,5);// 定义收盘价的5周期均线(C为CLOSE简写)。例3:A:=REF(C,1);// 取得前一根k线的收盘价。

超哥量化的博客 1万+

关于的外连接(left join或right join)我们常犯的一个严重错误

关于的外连接(left join或right join)我们常犯的一个严重错误left join,right join ,我们常犯的一个错误就是以为条件写在on 后面和写在where里是一样的,我前几天刚遇到这样的问题,起初觉得很奇怪,明明觉得正确的sql却得到了意外的结果. 下表我们假设是testLeftJoin ,有两列,共三行数据:id | name --------------------

qinhl99的专栏-林鸿的技术博客 2万+

Android Studio中把llama.cpp编译Android .so

本文介绍了一个在Android Studio中集成llama.cpp的最小Demo实现方案,通过JNI将llama.cpp编译为Android.so库,实现本地加载GGUF模型进行文本生成。文章详细说明了项目结构配置(SDK≥30,NDK≥28)、CMake编译设置、Kotlin-JNI-C++的完整调用链实现,以及模型文件部署方式。该Demo采用每次请求新建上下文的简化设计,包含加载模型、生成文本、资源释放等核心功能,并提供了错误排查建议。项目舍弃了上下文保持等复杂功能以确保稳定性,适合作为端侧大语言模型

Zhang Phil 542

Impala重点问题列表

Impala重点问题列表(截止到1.01) 从目前的情况来看,impala的稳定性和易用性还有待提高,在生产环境中部署还存在比较大的风险。 未解决: ·          impala-shell命令不兼容Python 2.4 Impala 1.0.1中的impala-shell命令与Python 2.4不兼容, 后者是Red Hat 5的默认Python. Impala 1.0中的im

风之谷 2万+

从模糊到清晰:让AI教相机自动对焦的实战指南

AI自动对焦技术:让模糊照片成为过去式 深度学习驱动的自动对焦技术正颠覆传统摄影,使相机能在复杂场景下智能锁定焦点。相比传统对焦方法在弱光、低对比度环境下的失效,AI通过学习"清晰-模糊"规律,实现全场景精准对焦。本文详细解析了该技术的三大优势: 自适应各种光线条件; 毫秒级对焦速度; 突破物理限制的精度。 通过PyTorch搭建的CNN模型,展示了从数据采集到模型训练的全流程实战方案,包括使用拉普拉斯算子评估图像清晰度等关键技术。该技术已成功应用于手机摄影、工业检测、无人机航拍和安防监

LXY_LOVE36的博客 353

【30天从零玩转AI应用开发】第16篇:智能体Agent入门——ReAct框架原理+首个会思考、会动手的AI实战

摘要: 本文介绍了AI智能体(Agent)的核心概念及其与普通大模型(LLM)的区别。通过ReAct(Reason+Act)框架,智能体实现了自主思考、调用工具和分步执行的能力。文章详细讲解了LangChain Agent的四大组件,并推荐新手使用ZERO_SHOT_REACT_DESCRIPTION类型。最后提供了一个完整的智能体实战代码示例,该智能体具备数学计算和天气查询功能,能够自主选择工具完成任务,展示了AI从”被动回答“到”主动行动“的关键进化。

在上海谋生的软件喵记录喵生 632

mysql添加主键的坑

但是并不会给id进行命名这挖出了一个深埋在 MySQL 底层 20 年的“暗黑语法坑”。MySQL 居然真的允许这种写法!我们来看看 MySQL 到底背着你偷偷干了什么。

weixin_44955867的博客 232

使用curl命令出现fatal: unable to access ‘https://github.com/nvm-sh/nvm.git/‘: Encountered end of file的解决方案

本文主要介绍了使用curl命令出现fatal: unable to access ‘https://github.com/nvm-sh/nvm.git/’: Encountered end of file的解决方案,希望能对使用curl命令的同学们有所帮助。 文章目录 1. 问题描述 2. 解决方案

weixin_43178406的博客 1万+

MySQL 分片集群的备份别堆本地盘:用 Vitess 把备份落进 RustFS

Vitess 把 MySQL 拆成很多分片,一个分片跑在一台 tablet 上。备份要是还落在每台 tablet 自己的本地盘里,分片一多就散成一地,真要恢复的时候还得挨个去找哪台机器存了哪份。更现实的麻烦是本地盘一旦坏掉,那份备份跟着就没了,分片越密,单点越稠。Vitess 自带一套 S3 兼容的备份存储实现,能把每个分片的备份直接写进对象存储。用 RustFS 当这个 S3 后端,所有分片的…

分布式存储与RustFS的博客 906

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

MySQL 8.4.13 元数据锁(MDL)源码分析详解

MySQL 8.4.13中,元数据锁(MDL)支持11种锁模式与3种持有期限,用于保护表定义等元数据。常见模式如MDL_SHARED_READ(读操作)、MDL_SHARED_WRITE(写操作)及高优先级锁MDL_SHARED_HIGH_PRIO,其授予逻辑与事务生命周期相关。MDL与InnoDB行锁协同工作,确保并发访问安全。排查锁问题需结合锁类型、对象及持有期限综合分析。

CharlesYuangc的博客 352

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

MySQL Outbox、Redis Streams 与 LangGraph——如何构建可靠的异步 AI Agent

本文介绍异步任务架构中的三大核心组件:TransactionalOutbox确保任务与事件在数据库中一致;RedisStreams实现任务分发、消费确认与故障恢复;LangGraph编排Agent多步骤执行并支持状态恢复。三者协同解决任务持久化、消息可靠投递与执行可恢复性问题,适用于长耗时AIAgent任务场景。

Joy T的博客 465

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

MySQL 建了索引查询还是慢:explain 显示 type=ALL 的 3 种原因

建了索引 EXPLAIN 仍报 type=ALL,查询仍是全表扫描。根因是隐式转换、函数包裹与统计过期,修复靠改 SQL、改类型、刷统计。适用于 InnoDB 线上排查,MyISAM 另议。

昨日种种,皆成今我。今日种种,皆成新我。 273

MySQL 备份恢复(日志管理和备份)

MySQL日志用于排错、性能分析及数据恢复。主要日志包括错误日志(记录启动、关闭及运行错误)、通用查询日志(记录客户端所有操作)。通过配置文件my.cnf可指定日志路径,如log_error = error.log。使用SHOW VARIABLES LIKE 'log_error'查看错误日志位置。通用查询日志需开启general_log = ON并指定文件路径。日志对故障排查和数据恢复至关重要。

Y_P_W的博客 206

MySQL 性能优化:从 8 秒到 12 毫秒的实战之路

但要记住:目录怎么排,就得怎么查——跳过前面的条件,后面的就白建了。覆盖索引则是更进一步的优化:要查的列,索引里全都有,直接返回,省掉回表。这是一个贯穿始终的比喻:数据表是书架,每一行数据是一本书,数据库引擎是管理员,你的 SQL 就是借书请求。索引是有代价的:目录本身要占地方,每次新书上架、下架,目录也得跟着改,所以写入会变慢。差距不在硬件,不在网络——而在于数据库「找数据」的方式。它的学名叫 B+ 树,你可以把它想成书脊上的分层标签——先判断在 A-M 还是 N-Z,再缩小到小区间,几步就锁定。

R2028的博客 225

《阿里巴巴 Java 开发手册》的 MySQL 核心规范

既然你平时经常自己练习表结构设计,那这份提炼自《阿里巴巴 Java 开发手册》的 MySQL 核心规范,绝对是你日常建表和写 SQL 时的“避坑宝典”。我帮你把最核心的【强制】级别规范,按和。

qq_26889291的博客 336

MySQL 基本查询(下)

注意:8.0 的窗口函数在 5.7 中没有直接等价写法,通常要用自连接或用户变量模拟,迁移成本较高,需单独评估。注意:下面所涉及到的SQL代码都是兼容5.7版本,其字符集和校验规则是兼容5.7和8.0的写法。是原子操作,新旧表在一条语句内完成替换,避免“先删后插”中途失败导致数据不一致。CRUD 的操作对象是表,所以先给出完整、可直接执行的建表脚本。聚合,是为了满足 5.7/8.0 默认开启的。案例:删除表中的重复记录,重复数据只保留一份。作用:对查询到的结果进行列值更新。的查询结果直接插入到目标表中。

qq_73640809的博客 225

MySQL数据结构

示例如果显示的是 warning,说明其环境不是严格模式;5.7/8.0 默认开启。值,落在可打印 ASCII 范围的字节会显示为字符;

qq_73640809的博客 601

JDBC操作MySQL与SQL注入防范

因为之前做过一次事务回滚测试:插入了 id=20 的记录后。

2401_89953644的博客 216

Docker 实战:安装 MySQL 8 与搭建 Apache Doris 集群

在本地或测试环境中,用 Docker 部署数据库是最省事的方式。本文记录两件事:一是用 Docker 安装 MySQL 8.0.44,二是用 Docker Compose 搭建 Apache Doris 3.1.3 的 FE + BE 单节点集群。文中同时给出国内网络环境下配置镜像加速源的完整方案,避免拉取镜像时卡在docker.io。操作系统:Linux(CentOS 7+ / Ubuntu 20.04+ 均可),本文命令以 Linux 为例。

2401_83857914的博客 206

MySQL学生选课数据库

本文基于MySQL 8.0环境,设计并实现了一个学生选课数据库。通过分析需求,明确表结构与约束:student表含学号自增、姓名唯一、性别限定、系别默认值;course表为课程信息;sc表为选课记录,采用联合主键。建库后创建三张表,验证了数据约束(如性别检查、姓名唯一)及默认值生效。补充测试数据后,确认各约束正常工作,为后续视图等操作奠定基础。

s19134838482d的博客 286

一次MySQL延迟的分析

监控报警到群里。一看是主从延迟,我知道过一会能恢复,毕竟才几分钟。最怕的是那种拖几天的,那种可能得重建。第一眼看到的是。这是在等提交,第一反应就是:莫非有大事务?日志确实是集中在这一段时间里产生的。每个文件都没超过 1G,所以我当时的判断是:不是一个特别大的事务,而是几个连续的大事务。,同步追上了。报警是消失了,但还是想知道到底怎么回事。于是把这几个 binlog 拉下来,让 AI 帮着解析了一遍。然后我在自己进行分析。结论和我想的不一样。

xuexiaogang的专栏 228
上一篇: mysql参考(仅供自己参考)
下一篇: 学习mysql4.1的空间数据库特性(2)
飞羽飞之猪
博客等级 码龄21年 127粉丝 85原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址