简体   繁体   中英

Partial match between two MySQL tables

Table 1 'titles' ID Title 1 Tommy Hilfiger men 1790790 black watch

Table 2 'product' Supplier_name 1790790

I need to find the rows in table 1 where the table 2 supplier name is somewhere in the table 1 title, in this example '1790790' should be an expected result.

This query loads for ages and never completes:

SELECT * FROM `titles` t1
INNER JOIN product t2 ON t2.supplier_name LIKE CONCAT('%', t1.title, '%');

Where did I go wrong with this query?

I think a LEFT JOIN is what you want here

SELECT * FROM `titles` t1
LEFT JOIN product t2 ON t2.supplier_name LIKE CONCAT('%', t1.title, '%');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM