当前位置:网站首页>Summary of database problems
Summary of database problems
2022-07-02 04:51:00 【A red candle, a glass of Shaojiu】
Summary of strange problems
left join on and vs where
Scene description
Querying business data is , There are the following requirements . Need from
a
Remove from tableb
The data contained in the table . My first thought isa left join b on a.id = b.aid and b.aid is null
, Then the data came out . But I made a few discoveries ,a
There is ,b
There are also . So I was lost in thought .
Reappear
To build the data
CREATE TABLE `join_1` (
`id` int(11) DEFAULT NULL,
`address` varchar(255) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `join_2` (
`id` int(11) DEFAULT NULL,
`phone` varchar(255) DEFAULT NULL,
`thing` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Inquire about
select * from join_1 left join join_2 on join_1.id = join_2.id and join_2.phone is not null;
With and
The query results are as follows
It's obvious here that , I obviously don't want my mobile number to be
null
Of , But there is still something in the query results .. I have clearly added the conditions for judging the air ..
select * from join_1 left join join_2 on join_1.id = join_2.id where join_2.phone is not null;
With where
The query results are as follows
The query result here is exactly what I want . however
and
andwhere
What's the difference .
analysis
where
Statement occurs injoin
after , It's rightjoin
Filtering of resultson、and
sentence , It happened injoin
Before , The data is injoin
Is filtered in the process .
Here I useand
The query has a null value because ,join
Beforejoin_2
There is data in the table , Backleft join
And then it came outnull
Data .
边栏推荐
- Pit encountered in win11 pytorch GPU installation
- Getting started with pytest -- description of fixture parameters
- How to modify data file path in DM database
- Ten thousand volumes are known to all, and one page of a book is always relevant. TVP reading club will take you through the reading puzzle!
- Exposure X8 Standard Version picture post filter PS, LR and other software plug-ins
- DJB Hash
- 二叉树解题(一)
- Landing guide for "prohibit using select * as query field list"
- Beginner crawler - biqu Pavilion crawler
- 6.30年终小结,学生时代结束
猜你喜欢
VMware installation win10 reports an error: operating system not found
农业生态领域智能机器人的应用
Gin framework learning code
6月书讯 | 9本新书上市,阵容强大,闭眼入!
Cache consistency solution - how to ensure the consistency between the cache and the data in the database when changing data
Leetcode- insert and sort the linked list
Embedded-c language-8-character pointer array / large program implementation
将光盘中的cda保存到电脑中
cs架构下抓包的几种方法
What methods should service define?
随机推荐
Orthogonal test method and function diagram method for test case design
Exposure X8标准版图片后期滤镜PS、LR等软件的插件
奠定少儿编程成为基础学科的原理
Ognl和EL表达式以及内存马的安全研究
TypeScript类的使用
Learn AI safety monitoring project from zero [attach detailed code]
cs架构下抓包的几种方法
unable to execute xxx. SH: operation not permitted
Mysql表insert中文变?号的问题解决办法
Keil compilation code of CY7C68013A
Pytest learning ----- pytest Interface Association framework encapsulation of interface automation testing
社交媒体搜索引擎优化及其重要性
Let genuine SMS pressure measurement open source code
One step implementation of yolox helmet detection (combined with oak intelligent depth camera)
There is no prompt for SQL in idea XML, and the dialect setting is useless.
Tawang food industry insight | current situation, consumption data and trend analysis of domestic infant complementary food market
初学爬虫-笔趣阁爬虫
Embedded-c language-8-character pointer array / large program implementation
Leetcode- insert and sort the linked list
Virtual machine installation deepin system