【问题标题】:MySQL WHERE LIKE Statement : How to delete rows in a table where a column substring not equals a desired substring?MySQL WHERE LIKE 语句:如何删除表中列子字符串不等于所需子字符串的行?
【发布时间】:2020-10-29 14:57:45
【问题描述】:

我想删除 kontext(column_name) 值,这些值与 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)) 

我收到此错误

错误代码:1093。您不能在 FROM 子句中指定目标表 'fmea001' 进行更新

您知道执行删除语句的另一种方法吗?谢谢!

【问题讨论】:

    标签: mysql sql subquery left-join sql-delete


    【解决方案1】:

    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
    

    【讨论】:

    • 是的,你正确地跟着我,它有效!非常感谢!!
    猜你喜欢
    • 1970-01-01
    • 2021-12-31
    • 2021-06-24
    • 1970-01-01
    • 2013-08-24
    • 2010-12-27
    • 2015-12-02
    相关资源
    最近更新 更多