Remove Expired Cancelled Orders
Delete cancelled orders placed before 2025-01-01.
- DELETE
- Predicate safety
- Date filtering
Exercise brief
Understand the request
Data governance Cancelled orders before the 2025 retention boundary are eligible for deletion.
Data retention policy allows old cancelled orders to be removed from the active operations database.
Return
- Remove only records matching both retention conditions.
Constraints
- Keep all pending and completed orders.
- Treat 2025-01-01 as an exclusive cutoff.
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
orders
order_idINTEGERstatusVARCHAR(20)ordered_atDATE
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
DELETE removes rows, so make the retention rule explicit in the WHERE clause.
Hint 2
Combine status = 'cancelled' with a date earlier than 2025-01-01.
Hint 3
DELETE FROM orders WHERE status = 'cancelled' AND ordered_at < '2025-01-01';
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
DELETE FROM orders
WHERE status = 'cancelled' AND ordered_at < '2025-01-01';Why this works
Both status and time are required to translate the retention policy into a narrowly scoped deletion.
Success check
The expired cancelled order is gone and the three unrelated orders remain.
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Build the next SQL skill
WHERE Clause & Filtering
Practice SQL WHERE clauses with realistic boundary, NULL, text, date, exclusion, and production-filtering problems.
SQL Joins
Practice reliable INNER, LEFT, FULL, CROSS, self, semi, anti, range, temporal, and many-to-many join patterns.
Basic SQL Functions
Practice production-oriented string cleanup, numeric transformations, NULL handling, tolerant conversion, and delimiter parsing.
Open the interactive workspace and practice across SQL topics.