Mark Fischer
Mark Fischer

Reputation: 25

Is there a way to combine a SQL column with a LIKE

What I mean is this...

Is there a way to do something like this?

SELECT * FROM table WHERE column_a LIKE %column_b%

So that the content of column_a is searched in column_b. And when there is the word 'car' in column_a, and the words 'car parts' in column_b that would be a match.

Upvotes: 2

Views: 80

Answers (2)

J-16 SDiZ
J-16 SDiZ

Reputation: 26920

SELECT * FROM table WHERE column_a LIKE CONCAT('%', column_b , '%')

Upvotes: 3

3urdoch
3urdoch

Reputation: 7332

Use the CONCAT function like so

SELECT * FROM table WHERE column_a LIKE CONCAT('%',column_b,'%')

Upvotes: 6

Related Questions