MySQL WHERE LIKE 语句:如何删除 table 中列子字符串不等于所需子字符串的行?
MySQL WHERE LIKE Statement : How to delete rows in a table where a column substring not equals a desired substring?
我想删除 kontext(column_name) 值,这些值与作为 fmea 值不同于 null 的子字符串具有不同的子字符串。我可以通过此查询 select 这些值:
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))
我收到这个错误
Error Code: 1093. You can't specify target table 'fmea001' for update in FROM clause
您知道执行删除语句的另一种方法吗?谢谢!
MySQL dodes 不支持在子查询中重新调用正在修改(更新或删除)的 table。
如果我没听错的话,你可以把它写成 anti-left 连接:
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
我想删除 kontext(column_name) 值,这些值与作为 fmea 值不同于 null 的子字符串具有不同的子字符串。我可以通过此查询 select 这些值:
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))
我收到这个错误
Error Code: 1093. You can't specify target table 'fmea001' for update in FROM clause
您知道执行删除语句的另一种方法吗?谢谢!
MySQL dodes 不支持在子查询中重新调用正在修改(更新或删除)的 table。
如果我没听错的话,你可以把它写成 anti-left 连接:
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