6.4

The Subquery In a Delete Statement

The Subquery in a DELETE statement

NOTE: Before you can run a DELETE or UPDATE statement without a WHERE clause, you must uncheck “Safe Updates” checkbox in MySQL Preference. Please see below.

sub_04.png

Code Sample:

USE world;
DELETE FROM city_bak
WHERE CountryCode IN
    (SELECT code FROM country
        WHERE region = 'Central Africa');

Results:

sub_05.png

USE world;

DELETE FROM city_bak

WHERE CountryCode IN

(SELECT code FROM country

     WHERE region = 'Central Africa');

CC BY-NC-ND International 4.0

CC BY-NC-ND International 4.0: This work is released under a CC BY-NC-ND International 4.0 license, which means that you are free to do with it as you please as long as you (1) properly attribute it, (2) do not use it for commercial gain, and (3) do not create derivative works.