问题描述
我想删除kontext(column_name)值,该值的substrinct与fmea值不同于null的substrinct不同。我可以通过此查询选择这些值:
select *
FROM fmea001
where substring_index(kontext,".",1)
not in (Select substring_index(kontext,1)
from fmea001
where fmea is not null
and lkey = 9)
但是,当我尝试删除
delete *
FROM fmea001
where substring_index(context,1)
not in (Select substring_index(context,1)
from fmea001
where fmea is not null
and lkey = 9))
我收到此错误
解决方法
MySQL并不支持在子查询中重新响应正在修改的表(更新或删除的表)。
如果我正确地跟随您,则可以将其写为反左联接:
delete f
from fmea001 f
left join fmea001 f9
on substring_index(f9.kontext,'.',1) = substring_index(f.kontext,1)
and f9.fmea is not null
and f9.lkey = 9
where f9.fmea is null