Markus
Markus

Reputation: 4038

mysql join where one field is a part of a field in a other table

I'm looking for something like this:

SELECT german_subsidiaries.*, customers.* 
FROM german_subsidiaries INNER JOIN customers 
ON customers.name LIKE '%'+german_subsidiaries.searchable_name+'%'

unfortunately this doesn't work,

Any idea where I can make a like to be a part of a join statement? And to make this like operation compare two different fields?

Upvotes: 0

Views: 316

Answers (1)

safarov
safarov

Reputation: 7804

Use CONCAT() function to merge strings in MYSQL

SELECT german_subsidiaries.*, customers.* 
FROM german_subsidiaries 
INNER JOIN customers ON customers.name 
LIKE CONCAT('%', german_subsidiaries.searchable_name, '%')

Upvotes: 5

Related Questions