Hard Writes & indexes Premium

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_idtitlealbum_idduration_seconds
1Come Together1259
2Something1182
3Here Comes the Sun1185
albums 18 rows
  • album_id integer PK
  • title text
  • artist_id integer → artists
  • release_year integer
album_idtitleartist_idrelease_year
1Abbey Road11969
2Sgt. Pepper's Lonely Hearts Club Band11967
3The White Album11968

Keep going