views:

147

answers:

4

I have mysql table that has a column that stores xml as a string. I need to find all tuples where the xml column contains a given string of 6 characters. Nothing else matters--all I need to know is if this 6 character string is there or not.

So it probably doesn't matter that the text is formatted as xml.

Question: how can I search within mysql? ie SELECT * FROM items WHERE items.xml [contains the text '123456']

Is there a way I can use the LIKE operator to do this?

Thanks

+1  A: 
SELECT * FROM items WHERE `items.xml` LIKE '%123456%'

The % operator in LIKE means "anything can be here".

Coronatus
A: 

you mean:

SELECT * FROM items WHERE items.xml '%123456%'

?

pulegium
did you miss a LIKE ?
alex
A: 

Why not use LIKE?

SELECT * FROM items WHERE items.xml LIKE '%123456%'
systempuntoout
+3  A: 
Mike Cialowicz
@Mike... how would I modify this to use with a PHP query? I have a string `$message` and I'd like to select the row with that exact string. I have `SELECT * FROM Messages WHERE from_id = '$fromID' AND to_id = '$toID' AND message LIKE '$message'` but I don't think that works
Hristo