问题
In MySQL, I would like to do a FULLTEXT search on a table 'articles'. The text I want to search against would be located in another table, 'Vectors' under the column 'CVs'
I am trying:
SELECT website
FROM articles
WHERE MATCH (title, body)
AGAINST(
SELECT CVs
FROM Vectors
WHERE Title="cv1")
However, it keeps returning syntax error.
Is it possible to run a subquery in the AGAINST clause?
回答1:
You would like to be able to do:
SELECT website
FROM articles cross join
vectors
WHERE title = 'cv1' and MATCH (title, body) AGAINST(cv);
But, the argment in against
needs to be a constant.
You can resort to:
SELECT website
FROM articles cross join
vectors
WHERE title = 'cv1' and
(title like concat('%', cv, '%') or body like concat('%', cv, '%'))
回答2:
From the documentation
The search string must be a literal string, not a variable or a column name.
You probably need to use LIKE instead of MATCH, though you should note that it will be much slower.
来源:https://stackoverflow.com/questions/15735562/using-a-subquery-in-the-against-for-a-fulltext-search-in-mysql