Current demand:There are two tables, group and factor. One group corresponds to multiple factors. Now we want to query the valid groups and the corresponding valid factors . Both tables have the isDel logical deletion flag. The first mistake :SELECT g.*,f.* FROM groups g LEFT JOIN factor f ON f.groupId = g.id where g.isDel=0 and f.isDel=0 The LEFT JOIN keyword returns all rows from the left table (table_name1), even if there are no matching rows in the right table (table_name2). Wrong way of writing:SELECT g.*,f.* FROM groups g LEFT JOIN factor f ON f.groupId = g.id and g.isDel=0 and f.isDel=0 This way of writing Cause Analysis:Several knowledge points about where and on conditions in left join:
Correct way to write it:SELECT g.*,f.* FROM groups g LEFT JOIN factor f ON f.groupId = g.id and f.isDel=0 where g.isDel=0 in conclusion: 1. To add conditional restrictions to the left table, add them in the where condition and do not put them after on. This is the end of this article about analyzing the problem of using left join to add where conditions in MySQL. For more relevant content about adding where to MySQL left join, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: JavaScript to implement search data display
>>: 10 Underused or Misunderstood HTML Tags
The Docker container that has been running shows ...
filter is generally used to filter certain values...
Text Shadow text-shadow: horizontal offset vertic...
Table of contents 1:mysql execution process 1.1: ...
State Hooks Examples: import { useState } from ...
Import and export of Docker images This article i...
Table of contents Data volume Anonymous and named...
The effect of completing a menu bar through displ...
The insignificant flex-basis has caused a lot of ...
MQTT Protocol MQTT (Message Queuing Telemetry Tra...
Solution Abandon the Linux virtual machine that c...
CSS3 achieves cool 3D rotation perspective 3D ani...
The format is simple: proxy_pass URL; The URL inc...
1. Introduction to Flex Layout Flex is the abbrev...
If you want to insert 5 records into table1, the ...