Home > database >  Is there a way to filter string by various criteria?
Is there a way to filter string by various criteria?

Time:03-10

I'm trying to pull a list of product names. In MySQL, is there a way to filter string values in the below criteria under the Where clause?

  • Product name should have more than 1 word
  • Product name cannot just be a number

As a reference, I'm working with an extremely simple query:

FROM organization                       
JOIN product on o.id = p.id                         
JOIN customer on c.id = o.id 

CodePudding user response:

You can use regular expressions.

This would select product names that are not made of numbers only, and that contain at least one space (thus having more than 1 word) :

WHERE `product_name` NOT REGEXP '^[[:digit:]]*$'
AND `product_name` REGEXP '[[:space:]] '

More info on how to use regular expressions on that website.

  • Related