4

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
1
  • 1
    Either use FIND_IN_SET instead of LIKE, or restructure your database and normalize your multiple group_ids into a separate relational table Commented Sep 27, 2012 at 6:48

1 Answer 1

2

Instead of using LIKE use FIND_IN_SET function, try this:

SELECT * 
FROM Table_One 
WHERE FIND_IN_SET(".$objectData[groupid].", Table_One.groupid); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.