mysql - Mysql 查询中出现 LIKE %...% 错误

标签 mysql sql

我正在尝试使用另一个表更新一个表。我无法确定如何在此处使用 LIKE %...% 功能。请帮帮我。

表1:

待更新表格:

id | location | value
------------
1  | california | I am going to be here soon.
2  | Nill | Hello I love playing chess and yes.
3  | Nill | my hotel room is just shitty!
4  | Nill | Why on earth God doesn’t live on earth!
5  | Nill | friends of friends and their dogs.

表2:

表格到检查来源:

uniqueid | location | keyword
---------------------
1        | Texas | Why on earth
2        | NewYork   | friends and their
3        |   Washington | love playing chess
4        | NewYork   | their dogs

结果应该是:

id | location | value
------------
1  | California | I am going to be here soon.
2  | Washington | Hello I love playing chess and yes.
3  | Nill | my hotel room is just shitty!
4  | Texas | Why on earth God doesn’t live on earth!
5  |NewYork| friends of friends and their dogs.

——

我正在使用这个公式,但它给了我持续的错误:

UPDATE TableToBeUpdated, TableToCheckFrom
SET TableToBeUpdated.location = TableToCheckFrom.Location
WHERE TableToBeUpdated.Value LIKE %TableToCheckFrom.Keyword%

提前致谢!

最佳答案

您需要将 % 放在引号中并将它们连接到关键字。您需要连接两个表,以便可以引用两个表中的列。

UPDATE TableToBeUpdated AS u
JOIN TableToCheckFrom AS c ON u.Value LIKE CONCAT('%', c.Keyword, '%')
SET u.location = c.Location

关于mysql - Mysql 查询中出现 LIKE %...% 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36808590/

相关文章:

javascript - intel xdk 将 mySQL 数据库连接到应用程序

mysql - 查询查询中有大量匹配项的大表

sql - Rails、ActiveRecord、嵌套模型上具有多个联接的复杂查询

sql - 如果行有关系,如何插入 BIT 值

mysql - SQL从指定类别及其子项中选择所有产品

mysql - SQL 查询从多个 tag_id 中选择唯一图像

php - 从 db 查询 blob 时,如何在查询中将 blob 转换为文本?

PHP MYSQL 错误,查询无效(但不是无效的)

mysql - sql 计数当前用户标识添加的行数(视频)

来自三个不同表的 MySQL 查询