| Get column if it has a word
|
radiator251

msg:4071224 | 10:31 pm on Jan 30, 2010 (gmt 0) | This should be pretty easy...I'm trying to select rows in which the `description` column has a certain word. I tried "...WHERE `description` LIKE '{$word}'" but I guess without any helper symbols (_ or %), LIKE is equivalent to '='. How else would I do this? To clarify, I want to prevent any rows from being displayed if the query is looking for "bar" and the description has the word "barcode". Thanks.
|
whoisgregg

msg:4071302 | 2:05 am on Jan 31, 2010 (gmt 0) | You can use a regular expression search for word boundaries, but you'll probably want to combine that with a LIKE '%bar%" first to reduce the number of rows checked by the regular expression. Something like this (untested code off the top of my head): SELECT * FROM `table` WHERE `description` LIKE '%bar%' AND `description` REGEXP '[[:<:]]bar[[:>:]]'; |
| This should match 'bar' without matching 'barcode'. REGEXP Documentation: [dev.mysql.com...]
|
radiator251

msg:4071570 | 7:54 pm on Jan 31, 2010 (gmt 0) | Ok cool, I didn't know you could use regular expressions in MySQL. However, when I put that in I get an error in my php, "unexpected '['". I'd assume I have to escape some of those characters...do you know which ones?
|
|
|