jeff5656 Posted December 15, 2010 Share Posted December 15, 2010 Could someone please help me with the code that will select records only if there are certain keywords in two of the fields? for instance: $query = "select * from table_a where (column_a REGEXP 'apple' OR 'kiwi') OR (column_b REGEXP 'apple' OR 'kiwi) WHERE status = 'active' "; So if the record contains apple or kiwi anywhere in column_a OR column_b, then select that record. I know you have to use regexp because the contents of column_a is a big text with a few sentences or paragraphs of text, and I only want to select the record if it contains those two words (and same for column_b). Quote Link to comment https://forums.phpfreaks.com/topic/221769-regular-expression-in-a-query/ Share on other sites More sharing options...
Maq Posted December 15, 2010 Share Posted December 15, 2010 Not sure what's more expensive LIKE or REGEXP but I would assume REGEXP. Why can't you use LIKE for each column? Also, I don't think you need to separate your logic with parentheses if all your logical operators are ORs. Quote Link to comment https://forums.phpfreaks.com/topic/221769-regular-expression-in-a-query/#findComment-1147731 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.