Mysql query to get matching records

Table_one

id name groupid 1 AAA 5,6 2 BBB 5,7 3 CCC 15 

I am trying to make a query something like this:

 select * from Table_One where Table_One.groupid like '%".$objectData[groupid]."%' 

so if the value of $objectData[groupid] is 5, then the result should be

 1 AAA 5,6 2 BBB 5,7 

Similarly, if the value of $objectData[groupid] is 6, then the result should be

 1 AAA 5,6 

and if the value of $objectData[groupid] is 7, then the result should be

 2 BBB 5,7 
+4
source share
1 answer

Instead of using LIKE use FIND_IN_SET , try the following:

 SELECT * FROM Table_One WHERE FIND_IN_SET(".$objectData[groupid].", Table_One.groupid); 
+2
source

Source: https://habr.com/ru/post/1436527/


All Articles