当前位置:网站首页>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
aRemove from tablebThe 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 ,aThere is ,bThere 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
nullOf , 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
andandwhereWhat's the difference .
analysis
whereStatement occurs injoinafter , It's rightjoinFiltering of resultson、andsentence , It happened injoinBefore , The data is injoinIs filtered in the process .
Here I useandThe query has a null value because ,joinBeforejoin_2There is data in the table , Backleft joinAnd then it came outnullData .
边栏推荐
- Let genuine SMS pressure measurement open source code
- The solution to the complexity brought by lambda expression
- CorelDRAW Graphics Suite2022免费图形设计软件
- 奠定少儿编程成为基础学科的原理
- 数学知识——快速幂的理解及例题
- Mapping location after kotlin confusion
- How to recover deleted data in disk
- Realize the function of data uploading
- [Yu Yue education] autumn 2021 reference materials of Tongji University
- Comp 250 parsing
猜你喜欢

Thinkphp內核工單系統源碼商業開源版 多用戶+多客服+短信+郵件通知

Rhcsa --- work on the third day

将光盘中的cda保存到电脑中

Learn BeanShell before you dare to say you know JMeter

Mysql database learning

Tawang food industry insight | current situation, consumption data and trend analysis of domestic infant complementary food market

Practical problem solving ability of steam Education

ThinkPHP kernel work order system source code commercial open source version multi user + multi customer service + SMS + email notification

Starting from the classification of database, I understand the map database

Exposure X8标准版图片后期滤镜PS、LR等软件的插件
随机推荐
LeetCode-归并排序链表
Oracle stored procedure and job task setting
Starting from the classification of database, I understand the map database
Future trend of automated testing ----- self healing technology
Rhcsa --- work on the third day
Deep understanding of lambda expressions
Ognl和EL表达式以及内存马的安全研究
初学爬虫-笔趣阁爬虫
oracle 存储过程与job任务设置
Ruby replaces gem Alibaba image
CorelDRAW Graphics Suite2022免费图形设计软件
UNET deployment based on deepstream
js面试收藏试题1
培养中小学生对教育机器人的热爱之心
Orthogonal test method and function diagram method for test case design
Getting started with pytest ----- confitest Application of PY
Unit testing classic three questions: what, why, and how?
Steam教育的实际问题解决能力
How to write a client-side technical solution
GeoTrust ov multi domain SSL certificate is 2100 yuan a year. How many domain names does it contain?