【问题标题】:How to delete from table with join如何使用连接从表中删除
【发布时间】:2021-03-30 05:19:55
【问题描述】:

我在加入 MUSEUM 表时尝试从 PAINTING 表中删除。我正在运行的查询给了我一条错误消息“ORA-00933:SQL 命令未正确结束”。作为参考,我在下面粘贴了我的查询。

DELETE FROM PAINTING
    INNER JOIN MUSEUM ON PAINTING.Museum_Name = MUSEUM.MuseumName
    WHERE MUSEUM.MuCountry = 'France' OR MUSEUM.MuCountry = 'Spain';

【问题讨论】:

    标签: sql oracle subquery inner-join sql-delete


    【解决方案1】:

    在 Oracle 中,您将使用相关子查询。

    delete from painting p
    where exists (
        select 1 from museum m where pm.museum_name = m.museum_name and m.mu_country = 'France'
    )
    

    【讨论】:

    • 好的,这适用于删除来自法国的所有绘画。如果我还想从西班牙删除绘画,我可以在末尾添加“OR m.MuCountry = 'Spain'”吗?
    • @hasse: and (and m.mu_country = 'France' or and m.mu_country = 'Spain') - 括号在这里很重要。但是in 更好:and m.mu_country in ('France', 'Spain')。或者:
    猜你喜欢
    • 2010-11-07
    • 2013-01-16
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-30
    相关资源
    最近更新 更多