当前位置:网站首页>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 .
边栏推荐
- Mysql database learning
- 06 装饰(Decorator)模式
- Leetcode merge sort linked list
- 万卷共知,一书一页总关情,TVP读书会带你突围阅读迷障!
- Rhcsa --- work on the fourth day
- Common errors of dmrman offline backup
- 洛谷入门3【循环结构】题单题解
- Online incremental migration of DM database
- What data does the main account of Zhengda Meiou 4 pay attention to?
- geotrust ov多域名ssl證書一年兩千一百元包含幾個域名?
猜你喜欢
Solution: the agent throws an exception error
Unit testing classic three questions: what, why, and how?
Virtual machine installation deepin system
Idea autoguide package and autodelete package Settings
Vmware安装win10报错:operating system not found
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!
Analyze the space occupied by the table according to segments, clusters and pages
[understand one article] FD_ Use of set
Federal learning: dividing non IID samples according to Dirichlet distribution
List of common bugs in software testing
随机推荐
LeetCode-归并排序链表
Let正版短信测压开源源码
idea自动导包和自动删包设置
Unity particle Foundation
汇编语言中的标志位:CF、PF、AF、ZF、SF、TF、IF、DF、OF
Knowledge arrangement about steam Education
Several methods of capturing packets under CS framework
正大美欧4的主账户关注什么数据?
One click generation and conversion of markdown directory to word format
Cache consistency solution - how to ensure the consistency between the cache and the data in the database when changing data
CY7C68013A之keil编译代码
6月书讯 | 9本新书上市,阵容强大,闭眼入!
Tawang food industry insight | current situation, consumption data and trend analysis of domestic infant complementary food market
Hcip day 17
Win10 disk management compressed volume cannot be started
Idea autoguide package and autodelete package Settings
Pytest learning ----- pytest Interface Association framework encapsulation of interface automation testing
Acelems Expressway microgrid energy efficiency management platform and intelligent lighting solution intelligent lighting tunnel
CorelDRAW graphics suite2022 free graphic design software
Arbre binaire pour résoudre le problème (2)