000
000

Reputation: 3950

mysql query to fetch 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:

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

such that if value of $objectData[groupid] is 5 then result should be

1  AAA   5,6
2  BBB   5,7

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

1  AAA   5,6

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

2  BBB   5,7

Upvotes: 4

Views: 126

Answers (1)

Omesh
Omesh

Reputation: 29071

Instead of using LIKE use FIND_IN_SET function, try this:

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

Upvotes: 2

Related Questions