I want to match column only if it is not empty
select *
from users
where message = 'test' AND phone like '%813%'
Where condition should be called only if phone column is not null
else below query should be called
select * from users where message = 'test'
means AND phone like '%813%'
should be called only if phone is not null
Use CASE
select *
from users
where message = 'test' AND
case when phone is not null
then phone like '%813%'
else 1 end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.