4

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
halfer
  • 19,824
  • 17
  • 99
  • 186
Query Master
  • 6,989
  • 5
  • 35
  • 58

1 Answers1

7

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.

Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452