Search code examples
sqloracle-databasesubqueryinner-joinsql-delete

How to delete from table with join


I am trying to delete from the PAINTING table while joining with the MUSEUM table. The query I am running is giving me an error saying "ORA-00933: SQL command not properly ended". For reference I have pasted my query below.

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

Solution

  • In Oracle, you would use a correlated subquery.

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