jj172
jj172

Reputation: 809

Compare to a substring of a variable in MySQL?

I have a query where I have a variable that is a string, and I want to select all columns that contain a subset of that string. What is the simplest way to do this?

For example, I have:

SELECT * FROM table WHERE
value [IS A SUBSTRING OF] variable

So if my variable was something like 'ABCDEFG', I would like to find all values that are equal to 'A', 'AB', 'ABC', ... etc.

What would be the best way to go about this?

Thank you!

Upvotes: 0

Views: 756

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 1549

select * 
from table 
where col1  like '%var%' or col2  like '%var%' or col3 like '%var%'

Upvotes: 1

Related Questions