The WHERE predicate supports subqueries, including IN, NOT IN, EXISTS, NOT EXISTS, and scalar subqueries. The following types of subqueries are not supported:
Nested subqueries, that is, an subquery inside another subquery
NOT IN subquery inside an OR, for example, a = 3 OR b NOT IN (SELECT c from t)
In most cases, you can rewrite NOT IN subqueries using NOT EXISTS. We recommend using
NOT EXISTS whenever possible, as DELETE with NOT IN subqueries can be slow.
Examples
SQL
> DELETEFROMeventsWHEREdate < '2017-01-01'
> DELETEFROM all_events
WHERE session_time < (SELECTmin(session_time) FROM good_events)
> DELETEFROM orders AS t1
WHEREEXISTS (SELECToidFROM returned_orders WHERE t1.oid = oid)
> DELETEFROMeventsWHEREcategoryNOTIN (SELECTcategoryFROM events2 WHEREdate > '2001-01-01')