Example 1
Copy only recently active users into a separate table
INSERT INTO recent_users (id, name) names the destination columns. The SELECT clause filters to users with a last_active date in 2025 or later, which excludes Alice. The column list in the INSERT clause must match the SELECT list in both count and compatible types. The final SELECT confirms that Bob and Carol were copied.
CREATE TABLE users (id INT, name VARCHAR(50), last_active DATE);
CREATE TABLE recent_users (id INT, name VARCHAR(50));
INSERT INTO
users
VALUES
(1, 'Alice', '2024-01-15'),
(2, 'Bob', '2025-11-20'),
(3, 'Carol', '2025-12-01');INSERT INTO
recent_users (id, name)
SELECT
id,
name
FROM
users
WHERE
last_active >= '2025-01-01';
SELECT
id,
name
FROM
recent_users
ORDER BY
id;| id | name |
|---|---|
| 2 | Bob |
| 3 | Carol |
The INSERT INTO ... SELECT syntax is identical across all supported engines.