MySQL Update使用全文搜索

时间:2022-09-19 19:10:46
UPDATE mytable SET this = 'this' AND that = 'that'
WHERE MATCH (items) AGAINST ('item5')

The problem is this query will perform an UPDATE on every match found, instead of the desired result which is to update the first row matched.

问题是此查询将对找到的每个匹配执行UPDATE,而不是更新匹配的第一行所需的结果。

Adding LIMIT 0, 1 to the query results in a MySQL Syntax Error. Is there a way to do this update on the first record found using a fulltext query?

将LIMIT 0,1添加到查询会导致MySQL语法错误。有没有办法在使用全文查询找到的第一条记录上执行此更新?

1 个解决方案

#1


3  

According to the documentation of update, you can use :

根据更新文档,您可以使用:

[LIMIT row_count]

And not, like you did :

而不是像你一样:

LIMIT 0, 1


So, in your case, your query would look like this :

因此,在您的情况下,您的查询将如下所示:

UPDATE mytable SET this = 'this' AND that = 'that'
WHERE MATCH (items) AGAINST ('item5')
LIMIT 1

#1


3  

According to the documentation of update, you can use :

根据更新文档,您可以使用:

[LIMIT row_count]

And not, like you did :

而不是像你一样:

LIMIT 0, 1


So, in your case, your query would look like this :

因此,在您的情况下,您的查询将如下所示:

UPDATE mytable SET this = 'this' AND that = 'that'
WHERE MATCH (items) AGAINST ('item5')
LIMIT 1