Mysql - how to use like on multiple columns

Viewed 12417

I've searched in mysql query a word in multiple column in java program. The number of column is variable. It is correct this query:

select * from customer with (city, name) like%'adelaide'%
4 Answers

It's better to use CONCAT_WS() function.

CONCAT() returns NULL if any argument is NULL.

CONCAT_WS() skip any NULL values after the separator argument.

multiple like statements can not be used with or directly. You have to use column name for each like statement.

Use multiple like as mentioned below.

Select * 
from animals 
where 
(
[animalscolumn] like ('%dog%') or 
[animalscolumn] like ('%cat%') or 
[animalscolumn] like ('%gerbil%') or 
[animalscolumn] like ('%hamster%') or 
[animalscolumn] like ('%guinea pig%')
)
select * from customer with city like%'adelaide'% or name like%'adelaide'%
Related