mysqlsubqueryfull-text-searchmatch-against

subquery (Incorrect arguments to AGAINST) using Mysql


When I execute this query with MATCH AGAINST using MySql (see Query 1st) the issue in this query they has generated an error like this (see error) or when I execute the same query with = they executed normally(see Query 2nd).

My question is what am I doing wrong with against statement?

Query 1st

SELECT (SELECT COUNT(up.`user_id`) 
FROM `users_post` up WHERE MATCH (up.`user_id`) AGAINST (uf.`user_id`)) 
AS user_count 
FROM `users` uf

Error

enter code hereError Code : 1210
Incorrect arguments to AGAINST
(0 ms taken)

Update

Query 2nd

SELECT 
(SELECT COUNT(up.`user_id`) 
FROM `users_post` up WHERE up.`user_id` = uf.`user_id`) 
AS user_count 
FROM `users` uf

Solution

  • The problem is that the argument for AGAINST must be a literal string, for example 'Fred'. It is not allowed to use a column name like uf.user_id.

    MATCH (up.`user_id`) AGAINST (uf.`user_id`)
    --                            ^^^^^^^^^^^^ not allowed!
    

    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.