MySQL join query using like? MySQL join query using like? mysql mysql

MySQL join query using like?


Try

SELECT *FROM Table1INNER JOIN Table2 ON Table1.col LIKE CONCAT('%', Table2.col, '%')

MySQL does string concatenation differently from other databases, so in case you want to port your app, you need to have an alternate version where || is used as concatenation operator, as mentioned by Michael in another answer. This operator doesn't work in MySQL though, since it means or.


How about this instead:

SELECT * FROM Table1, Table2 WHERE Table1.col LIKE '%'+Table2.col+'%';

Since you're selecting everything from both tables anyway, this would probably get you there.


SELECT p.products_id, pd.products_name, p.products_modelFROM products_description pdJOIN products p ON p.products_id = pd.products_idWHERE pd.products_name LIKE CONCAT( '%', p.products_model, '%' )LIMIT 0 , 100

First off you have to restrict your request by (p.products_id = pd.products_id) and LIMIT. And look what time it took. After that you can go and make comparison with (WHERE). If you gonna compare directly within JOIN you will put down your db if there are at list 20 thousands items. Beware.)