假设MySQL数据库中有两列名为first
和second
。
我想在second
中搜索first
的值并删除它。
例子:
第一行:first
是:test
,second
是:Hello, this is a test!
预期结果:second
是:Hello, this is a !
我想这不难,但我不知道怎么做。
有人能帮我吗?
最佳答案
对于查询,应该这样做。
SELECT
REPLACE(second, first, '')
FROM your_table;
更新:
UPDATE your_table SET second = REPLACE(second, first, '');
正如@Gordon在下面的注释中提到的,添加一个where子句来仅对所需的行进行更新:
UPDATE your_table SET second = REPLACE(second, first, '')
WHERE second like concat('%', first, '%');