Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare 2 tables using match

I have 2 tables table1 and table2. Table1 consist of paragraph which is a news article including some company codes/names, while table2 is a dictionary consist of 2 columns which are company code and the company name.

Using MYSQL FTS function MATCH i want to compare the article with all items/dictionary in table2 ( both of columns )

SELECT * FROM pyproject.table1 WHERE MATCH (Paragraph) against
(SELECT * FROM pyproject.table2' with query expansion);

It seems to produce an error

How to check whether the article matched with the dictionary, the data in table1 will be selected and the company code column in table2 is included/joined together with the data in table1.

So if the article in table1 consist of multiple company codes, it will be duplicated and added appropriate company codes

like image 667
FH337 Avatar asked Feb 20 '26 11:02

FH337


1 Answers

According to the reference that you've provided AGAINST doesn't work with columns. Instead you can use LIKE:

SELECT
    t1.Paragraph,
    t2.CompanyCode
FROM pyproject.table1 t1
INNER JOIN pyproject.table2 t2 ON (
    (t1.Paragrah LIKE CONCAT('%', t2.CompanyCode, '%')) OR
    (t1.Paragrah LIKE CONCAT('%', t2.CompanyName, '%'))
    )
;
like image 127
Nae Avatar answered Feb 22 '26 01:02

Nae



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!