Forum Moderators: coopster

Message Too Old, No Replies

where clauses and regexp or 'like'

to find one word in a field?

         

Trisha

12:36 am on Apr 14, 2004 (gmt 0)

10+ Year Member



I've got a table about colored widgets and I need to separate the red widgets from the blue ones, etc. But there is no field for color. The only way I can tell what color a particular widget is, is by looking at the description field.

Can I use something like:
where description LIKE '%red%'

to find the rows where the word 'red' is used somewhere in the description? According to my PHP book '%' is to be used as a wild card. I didn't really understand how it worked otherwise though, if you could really do something like this or not. Or is there a totally other way to pull out data based on a word or phrase found in one field?

Thanks!

ergophobe

12:44 am on Apr 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



First rule - try it and see what it does.

But yes, it does work as you say. It won't match just whole words though so
like '%red%' will match

red widgets
battered widgets
colored widgets

and so on

Trisha

2:42 am on Apr 14, 2004 (gmt 0)

10+ Year Member



Wow! That was amazingly easy!

A while back I needed to do something that it turned out I needed 'IN' for. Afterward I did find 'in' in my php book, but the description of what it did just didn't make any sense to me at all, I could not have understood what it did myself from reading that. So when I read what 'like' was supposed to do I had serious doubts that it would really do what I thought I understood it to do based on what my book said.

Anyway, thanks ergophobe! I still can't believe how easy it was to do that. I had been wanting to pull out information in a similar way for a while, but thought it would be really difficult!