当前位置:网站首页>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 .
边栏推荐
- Hcip day 17
- Binary tree problem solving (1)
- How to modify data file path in DM database
- AcrelEMS高速公路微电网能效管理平台与智能照明解决方案智慧点亮隧道
- Oracle stored procedure and job task setting
- Online incremental migration of DM database
- Record the bug of unity 2020.3.31f1 once
- Gin framework learning code
- 培养中小学生对教育机器人的热爱之心
- C - derived classes and constructors
猜你喜欢

Embedded-c language-8-character pointer array / large program implementation

How do I interview for a successful software testing position? If you want to get a high salary, you must see the offer

UNET deployment based on deepstream

My first experience of shadowless cloud computer

洛谷入门3【循环结构】题单题解

Mysql database learning

Idea autoguide package and autodelete package Settings

Typescript function details

win11安装pytorch-gpu遇到的坑

Precipitate yourself and stay up late to sort out 100 knowledge points of interface testing professional literacy
随机推荐
正大美欧4的主账户关注什么数据?
Embedded-c language-9-makefile/ structure / Consortium
Knowledge arrangement about steam Education
Common locks in MySQL
One click generation and conversion of markdown directory to word format
Lay the foundation for children's programming to become a basic discipline
10 minute quick start UI automation ----- puppeter
idea自动导包和自动删包设置
MySQL table insert Chinese change? Solution to the problem of No
C# 基于MQTTNet的服务端与客户端通信案例
Oracle stored procedure and job task setting
解析少儿编程中的动手搭建教程
Thinkphp內核工單系統源碼商業開源版 多用戶+多客服+短信+郵件通知
VMware installation win10 reports an error: operating system not found
Getting started with pytest ----- confitest Application of PY
How muddy is the water in the medical beauty industry with a market scale of 100 billion?
关于Steam 教育的知识整理
Ruby replaces gem Alibaba image
二叉树解题(二)
C language practice - binary search (half search)