Part 43: Inserting Data from Other Tables: INSERT INTO ... SELECT
Copying and transforming data between tables directly in the database engine.
1. Syntax
-- Archive inactive users into an archive table:
INSERT INTO archived_users (user_id, email, archived_at)
SELECT id, email, CURRENT_TIMESTAMP
FROM users
WHERE is_active = FALSE AND last_login < '2023-01-01';
Key Takeaways
- Perform ETL data migration completely in-memory inside the database with
INSERT INTO ... SELECT.
In Part 44, we explore Updating Rows with UPDATE & The Danger of Missing WHERE!

