Possible Duplicate:
mysql join query using like?
I want to do a join where one column contains a string from another table's column:
SELECT
a.first_name,
b.age
FROM names a
JOIN ages b
ON b.full_name LIKE '%a.first_name%'
Is this possible? I'm using MySQL. Of course the above query will not work since the LIKE '%a.first_name%' will just look for the string a.first_name, and not the column's actual value.
You only need to concatenate the strings, you could also do a search and replace.
SELECT
a.first_name,
b.age
FROM names a
JOIN ages b
ON b.full_name LIKE '%' + a.first_name + '%'