假设MySQL数据库中有两列名为firstsecond
我想在second中搜索first的值并删除它。
例子:
第一行:first是:testsecond是: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, '%');

10-07 19:24
查看更多