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
Install Apache from source 1. Upload the Apache s...
The syntax for an outer join is as follows: SELEC...
Trigger Introduction A trigger is a special store...
Table of contents 1. What is event delegation? 2....
This article shares the installation and configur...
By default, the table title is horizontally cente...
This article mainly introduces the sample code of...
Here are a few ways to remove it: Add the link dir...
Table of contents Preface Initialize the project ...
The main contents of this article are as follows:...
Copy code The code is as follows: <html> &l...
In our daily development work, text overflow, tru...
This article introduces 4 methods to achieve mask...
Table of contents principle Network environment p...
Table of contents Preface && Operator || ...