Forum Moderators: coopster

Message Too Old, No Replies

[mysql] search (1,2,3) in (1,2,3)..

About search more value in more value

         

webstyler

7:42 am on Jul 12, 2005 (gmt 0)

10+ Year Member



Hi to all, I have a mysql field name value.
In this I can have :
1
1,2
1,2,3,4,5,6
...

Now

I can make a select with WHERE rules where one or more value is contains in VALUE fieds.

For example I must check if 2 or 3 is contains in one VALUE field
$research_number="2,3"

So I must say
select ids from mytable where VALUE in ($research_number)

But isn't corrett because VALUE can be 2,8,1 and research exact corrispondance ..

How can "break" and research "more to more" ?

thks

coopster

11:40 am on Jul 12, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



One way would be to use an OR clause ...

WHERE
2 IN ($research_clause) OR
8 IN ($research_clause) OR
1 IN ($research_clause)

zomega42

1:46 pm on Jul 13, 2005 (gmt 0)

10+ Year Member



I'm a little confused about the question, but if it's how I'm interpreting it, then try this:

select ids
from mytable
where VALUE like '%1%'
or VALUE like '%2%'
or VALUE like '%8%'

This does pattern matching, I wouldn't recommend it on a very large database.

webstyler

2:19 pm on Jul 13, 2005 (gmt 0)

10+ Year Member



yes, I have already use syntax "where VALUE like '%1%' or VALUE like '%2%' or VALUE like '%8%' "..

but I would like know if exist chance to researh "array" on "array"..

thks ;)

lobo235

2:32 pm on Jul 13, 2005 (gmt 0)

10+ Year Member



If you have comma-separated data in a column you can use the FIND_IN_SET() [dev.mysql.com] function to see if a certain value exists in the comma-separated list. You would have to search for each item one at a time though since FIND_IN_SET() [dev.mysql.com] will only find one item in a comma-separated list.