当前位置:网站首页>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 .
边栏推荐
- Virtual machine installation deepin system
- CY7C68013A之keil编译代码
- Alibaba cloud polkit pkexec local rights lifting vulnerability
- DC-1靶场搭建及渗透实战详细过程(DC靶场系列)
- How to write a client-side technical solution
- Unit testing classic three questions: what, why, and how?
- Pytorch yolov5 exécute la résolution de bogues à partir de 0:
- Solution: the agent throws an exception error
- [improvement class] st table to solve the interval maximum value problem [2]
- Common locks in MySQL
猜你喜欢

Record the bug of unity 2020.3.31f1 once

Read "the way to clean code" - function names should express their behavior

Online incremental migration of DM database

One click generation and conversion of markdown directory to word format

Promise all()

Why can't you remember when reading? Why can't you remember- My technology learning methodology
![Introduction to Luogu 3 [circular structure] problem list solution](/img/fd/c0c5687c7e6e74bd5c911b27c3e19c.png)
Introduction to Luogu 3 [circular structure] problem list solution

Learn BeanShell before you dare to say you know JMeter

Let正版短信测压开源源码

Markdown编辑语法
随机推荐
Precipitate yourself and stay up late to sort out 100 knowledge points of interface testing professional literacy
Geotrust OV Multi - Domain Domain SSL Certificate rmb2100 per year contains several Domain names?
Solution of DM database unable to open graphical interface
Keil compilation code of CY7C68013A
Lay the foundation for children's programming to become a basic discipline
数学知识——快速幂的理解及例题
Change deepin to Alibaba image source
geotrust ov多域名ssl证书一年两千一百元包含几个域名?
Learn BeanShell before you dare to say you know JMeter
Landing guide for "prohibit using select * as query field list"
数学问题(数论)试除法做质数的判断、分解质因数,筛质数
Summary of common string processing functions in C language
List of common bugs in software testing
Lm09 Fisher inverse transform inversion mesh strategy
Record the bug of unity 2020.3.31f1 once
Thinkphp Kernel wo system source Commercial Open source multi - user + multi - Customer Service + SMS + email notification
10 minute quick start UI automation ----- puppeter
二叉树解题(一)
Oracle stored procedure and job task setting
Detailed process of DC-1 range construction and penetration practice (DC range Series)