Adam Taoufiq
Adam Taoufiq

Reputation: 49

MYSQL check if a table value is contained in a passed string

So basically im stuck in this problem. Let's say my string is this "IIS Blaise Pascal" and inside my table in mysql I have a field that contains "Blaise Pascal" how can i return that field with a query?

I have tried with LIKE %string% but it doesn't work

Upvotes: 0

Views: 23

Answers (2)

Slava Rozhnev
Slava Rozhnev

Reputation: 10163

I think this query can help you:

select
case 
  when field1 like '%Pascal%' then 'field1'
  when field2 like '%Pascal%' then 'field2'
  when field3 like '%Pascal%' then 'field3'
end as fieldname
from table
where 
  field1 like '%Pascal%' or
  field2 like '%Pascal%' or
  field3 like '%Pascal%'

Upvotes: 0

Nae
Nae

Reputation: 15335

I think you want:

SELECT *
FROM table t
WHERE "IIS Blaise Pascal" LIKE CONCAT('%', t.field, '%')
;

Upvotes: 1

Related Questions