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_id | name | |
|---|---|---|
| 1 | Alice | [email protected] |
| 2 | Bob | [email protected] |
| 3 | Charlie | [email protected] |
inactive_users 2 rows
- user_id integer PK
- name text
- email text
| user_id | name | |
|---|---|---|
| 4 | Carol | [email protected] |
| 5 | Dave | [email protected] |