Select datas from mysql where column value contains two strings
Discuss coding issues, and scripts related to PHP and MySQL.
-
MarPlo
- Posts:186
Select datas from mysql where column value contains two strings
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) )
Admin
Posts:805
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.