SQL interview question: DELETE Using a Subquery
Drop the Legacy Catalog
Licensing for the pre-1980 catalog expired at midnight. Every track on those albums has to go.
Write a single DELETE statement removing all tracks whose album was released before 1980.
Note: Your change is verified automatically and rolled back afterwards.
This challenge changes data. Your statement runs on a private copy of the database, then we check the resulting table.
Tables
tracks 40 rows
- track_id integer PK
- title text
- album_id integer → albums
- duration_seconds integer
| track_id | title | album_id | duration_seconds |
|---|---|---|---|
| 1 | Come Together | 1 | 259 |
| 2 | Something | 1 | 182 |
| 3 | Here Comes the Sun | 1 | 185 |
albums 18 rows
- album_id integer PK
- title text
- artist_id integer → artists
- release_year integer
| album_id | title | artist_id | release_year |
|---|---|---|---|
| 1 | Abbey Road | 1 | 1969 |
| 2 | Sgt. Pepper's Lonely Hearts Club Band | 1 | 1967 |
| 3 | The White Album | 1 | 1968 |