Medium Writes & indexes Free

SQL interview question: Copy Rows With INSERT ... SELECT

Archive the Churned User

User 3 (Charlie) hasn't logged in for a year. Policy says churned accounts move to the archive table.

Write a single INSERT ... SELECT statement copying user 3 from active_users into inactive_users (same columns: user_id, name, email).

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

active_users 3 rows
  • user_id integer PK
  • name text
  • email text
user_idnameemail
1Alice[email protected]
2Bob[email protected]
3Charlie[email protected]
inactive_users 2 rows
  • user_id integer PK
  • name text
  • email text
user_idnameemail
4Carol[email protected]
5Dave[email protected]

Keep going