INSERT INTO SELECT
INSERT INTO ... SELECT copies the result of a query into a table. It is handy for archiving rows or filling a summary table.
Example
CREATE TABLE top_students (name TEXT, score INTEGER);
INSERT INTO top_students (name, score)
SELECT name, score FROM students WHERE score >= 85;
SELECT * FROM top_students ORDER BY score DESC;Result
name | score Ada | 92 Zainab | 88 Amina | 85
Exercise
Fill a table from a query.
INSERT INTO archive SELECT * students;
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.