Search code examples
mysqlsql-like

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?


Solution

  • 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, '%')