I need to make a research by natural language on a mySQL table field taking as input the values of another table field. I tried something similar but, as I suspected, it was not correct:
SELECT id, name, MATCH(name),
AGAINST
(
SELECT name
FROM table2
) AS score
FROM table1
WHERE MATCH(name),
AGAINST
(
SELECT name
FROM table2
)
Any idea?
UPDATE 1
I followed the kind example here below but i got the error "#1064 - SQL query syntax error near 'tb2". I cannot see this syntax error. Here the code I am testing:
SELECT name, MATCH(name) AGAINST
(
(SELECT name
FROM
(
SELECT name
FROM active_ingredients
UNION ALL
SELECT active_ingredients.name as name
FROM active_ingredients
INNER JOIN temp_active_ingredients_aliases ON temp_active_ingredients_aliases.alias_name = active_ingredients.name
) tbl
GROUP BY name
HAVING count(*) = 1
ORDER BY name) tb2
) AS score
FROM
(
SELECT alias_name as name
FROM temp_active_ingredients_aliases
)
WHERE MATCH(name) AGAINST
(
(SELECT name
FROM
(
SELECT name
FROM active_ingredients
UNION ALL
SELECT active_ingredients.name as name
FROM active_ingredients
INNER JOIN temp_active_ingredients_aliases ON temp_active_ingredients_aliases.alias_name = active_ingredients.name
) tb3
GROUP BY name
HAVING count(*) = 1
ORDER BY name) tb4
)
The inner queries return the list of active_ingredients.name that do not exactly match at least one of the temp_active_ingredients_alieases.alias_name fields. So that I then try a match of the not exactly matching name(s) with the alias_name(s) by natural language FULLTEXT research. To be noted that the following inner queries are working properly:
SELECT name
FROM
(
SELECT name
FROM active_ingredients
UNION ALL
SELECT active_ingredients.name as name
FROM active_ingredients
INNER JOIN temp_active_ingredients_aliases ON temp_active_ingredients_aliases.alias_name = active_ingredients.name
) tbl
GROUP BY name
HAVING count(*) = 1
ORDER BY name
I am quite sure that the syntax error is very stupid, but i cannot see it.
UPDATE 2
Here the links to the code for generating the two tables (schema and some data)
Yiu were almost there
To explain a bit further.
db<>fiddle here
I corrected your mistakes
Without proper datqa, i can not test it, in can only remove syntax error