SQL- CROSS JOIN , LIKE . SUM , , GROUP_CONCAT:
SELECT t1.id, SUM(CASE WHEN t1.string LIKE CONCAT('%', t2.words, '%')
THEN 1
ELSE 0
END) AS WordCount,
GROUP_CONCAT(CASE WHEN t1.string LIKE CONCAT('%', t2.words, '%')
THEN t2.words
ELSE NULL
END) AS Words
FROM Table1 t1
CROSS JOIN Table2 t2
GROUP BY t1.id
. .
WARNING: CROSS JOINcan degrade the performance of large tables, since a Cartesian product (all possible combinations) runs between both sets, which can run quickly in millions.
source
share