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)
need Whether it is a Windows system or a Linux sy...
When we preview PDF on the page, some files canno...
Another important aspect of separating structure ...
1. Multiple borders[1] Background: box-shadow, ou...
I believe everyone is familiar with database inde...
Table of contents Date Object Creating a Date Obj...
This article mainly introduces the implementation...
Our bank's MGR will be launched at the end of...
In MySQL, fields of char, varchar, and text types...
Vulnerability Introduction The SigRed vulnerabili...
Table of contents MAH 1. Introduction to MAH Arch...
Table of contents Preface advantage: shortcoming:...
In a page, there are many controls (elements or ta...
There is no solution for Chinese input method und...
1. Create a docker network card [root@i ~]# brctl...