Delete with correlated EXISTS
SQL
Hard
3 views
Problem Description
Delete orders that have no order items (orphan orders).
Output Format
DML statement(s)
Sample Test Case
Input:
Orders, OrderItems
Output:
Orphan orders removed
Official Solution
DELETE FROM Orders o WHERE NOT EXISTS (SELECT 1 FROM OrderItems oi WHERE oi.order_id = o.order_id);
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!