[英]MySQL Remove part of string after specific character
I do got a database named "MAPPINGS" with about 23.000 rows I need to replace becouse of a mistake. 我确实有一个名为“ MAPPINGS”的数据库,大约有23.000行,由于错误,我需要替换它。 Is there any query to achieve the following:.
是否有任何查询可实现以下目的:
UPDATE MAPPINGS SET MAIN = 'firt part' WHERE USERID = '1578' AND MAIN LIKE 'first part >%'
The problem is that "first part" is every time something else. 问题在于“第一部分”每一次都是别的。 I just need to remove everyhing after the ">" than the MAPPINGS are correct.
我只需要删除“>”之后的所有内容,而不是MAPPINGS是正确的。
Or can this only be done by a PHP script? 还是只能通过PHP脚本来完成? while select * from mappings where userid = '1578' and then the update query.
而从userid ='1578'的映射中选择*,然后选择更新查询。 I hope there will be a query to achieve this.
我希望会有一个查询来实现这一目标。
You can do this in MySQL using substring_index()
: 您可以在MySQL中使用
substring_index()
:
UPDATE MAPPINGS
SET MAIN = SUBSTRING_INDEX(MAIN, '>', 1)
WHERE MAIN LIKE '%>%' AND USERID = '1578';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.