chase cabrera
chase cabrera

Reputation: 129

How to check if a string contains any string in a column MySQL

I'm trying to find if any word of a given string is contained within a column in a mySQL table.

Example

String: 'Company LLC'

Column: 'LLC'

I've tried the below query but no dice.

select * from table
where column sounds like '%Company LLC%'

Upvotes: 1

Views: 880

Answers (1)

Bohemian
Bohemian

Reputation: 425358

Try this:

select * from table
where column rlike replace('Company LLC', ' ', '|')

This does a regex match. In regex, the pipe char | means "or". The resulting regex means "Company or LLC". In MySQL, rlike matches when any part of the value matches (rather than the whole column matches), so you don't need ".*" on each end.

Upvotes: 3

Related Questions