【问题标题】:How to search for string from one column in other column and delete?如何从另一列的一列中搜索字符串并删除?
【发布时间】:2017-06-22 14:32:55
【问题描述】:

假设我的 MySQL 数据库中有两列名为 firstsecond

我想在second 中搜索first 的值并将其删除。

例子:

第一行:first 是:testsecond 是:Hello, this is a test!

预期结果:second 是:Hello, this is a !

我觉得应该不难,但是不知道怎么做。

谁能帮帮我?

【问题讨论】:

  • 需要更新表格吗?

标签: mysql sql search replace sql-delete


【解决方案1】:

对于查询,应该这样做。

SELECT
    REPLACE(second, first, '')
FROM your_table;

更新:

UPDATE your_table SET second = REPLACE(second, first, '');

正如@Gordon 在下面的 cmets 中提到的,添加一个 where 子句来仅对所需的行进行更新:

UPDATE your_table SET second = REPLACE(second, first, '')
WHERE second like concat('%', first, '%');

【讨论】:

  • update 应该有一个where 子句:where second like concat('%', first, '%')
猜你喜欢
  • 1970-01-01
  • 2017-04-25
  • 1970-01-01
  • 2016-06-11
  • 1970-01-01
  • 2019-07-20
  • 2015-12-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多