Page 1 of 1

Select datas from mysql where column value contains two strings

Posted: 09 Jan 2015, 06:48
by MarPlo
I want to search in mysql database with columns containing some specified names and the column has values like:
"Varsus GmbH (default)"
"Varsus Feinmechanik"
"Varsus xyz-something"

I need to get the result as an array where it contains results with columns containing exactly equal to "Varsus", if not then check for both "Varsus" and "default".
How to write a mysql query like this.

Now I've tried some thing like this:

Code: Select all

SELECT * FROM table WHERE suppliername = 'Bansbach' 
I need some thing like:

Code: Select all

 WHERE if(suppliername !='Bansbach' then (check it contains both Varsus and default) )

Select datas from mysql where column value contains two strings

Posted: 09 Jan 2015, 06:53
by Admin
Try this Select:

Code: Select all

SELECT * FROM table WHERE
  suppliername = 'Varsus'
OR (
    suppliername LIKE '%Varsus%'
    AND suppliername LIKE '%default%'
)
- The OR branch will only ever be taken, if the first condition fails.