Today, my colleague encountered a very strange problem when writing MYSQL query statements. When using MySQL multi-table query, a field in one table is used as the in query condition of another table, only one piece of information can be read, but it can be read normally if a number is used directly. The SQL statement is as follows: select a.id,a.title,b.idlist,b.aid from table a,table2 b where a.id in(b.idlist) and b.aid=2
The above statement can be used to query normally, but only one piece of information can be queried. However, the following statement can be used to read normally. select a.id,a.title,b.idlist,b.aid from table a,table2 b where a.id in(1,2,3,4) and b.aid=2 This is a very strange problem. I thought it was a data type problem at first, but to save data in the format of
OK, let's try it first and modify the original SQL statement to select a.id,a.title,b.idlist,b.aid from table a,table2 b where FIND_IN_SET(a.id,b.idlist) and b.aid=2 Execute the modified statement, and it can finally be read normally. After analyzing the reason, it is ultimately due to the data type problem. When we directly in(b.idlist), the b.idlist read is a character type, and in only accepts numbers. Although both have "," they are actually completely different. Well, the problem is solved. If you want to know more about how to use the FIND_IN_SET() function, you can read the related articles on the page. You may also be interested in:
|
<<: JS 9 Promise Interview Questions
>>: Install Windows Server 2019 on VMware Workstation (Graphic Tutorial)
Table of contents 1. Introduction 2. Deployment E...
This article shares the specific code of the vue-...
Table of contents Overview Same Origin Policy (SO...
Table of contents Preface interface type Appendix...
Table of contents Application Scenario Simply put...
Table of contents background Effect Ideas backgro...
We know that there are two ways to receive incomi...
This article provides some commonly used rewrite ...
This article lists the most commonly used image c...
Docker installation 1. Requirements: Linux kernel...
MySQL group sorting to find the top N Table Struc...
Use of stored procedure in parameters IN paramete...
The browser displays TIF format images Copy code T...
1. Download MySQL 1.1 Download address https://do...
Install vsftpd $ sudo apt-get install vsftpd -y S...