【mysql】update的in的嵌套查询更新,如果字段中包含字符串A,统一替换为字符串B

时间:2024-06-11 00:04:14

对于select的in嵌套子查询[DQL]:

select en_name from goods where uid in(
select uid from goods where goods_type_uid = '612ae65210a24ad88fc2faa6bd87c876'
)

而对于update等[DML]语句:

需要对子查询做一层临时表的包裹

UPDATE goods
SET en_name = REPLACE (en_name, 'brand ', '')
WHERE
uid IN (
SELECT
uid
FROM
(
SELECT
uid
FROM
goods
WHERE
goods_type_uid = '612ae65210a24ad88fc2faa6bd87c876'
AND en_name LIKE '%brand %'
) t
)