SQL INSERT INTO

INSERT INTO adds new rows to a table. Name the columns you’re filling, then give the values in the same order.

Updated December 1, 2026

Syntax

INSERT INTO table_name (column1, column2)
VALUES (value1, value2);

Insert one row

Add a new drink, then check the menu.

INSERT INTO drinks (id, name, category, price, calories, caffeinated)
VALUES (11, 'Iced Tea', 'tea', 3.75, 90, 1);

Check the result:

SELECT id, name, price
FROM drinks
WHERE id >= 9;
Result on the SQL Café sample data (3 rows)
idnameprice
9Hot Chocolate4
10Lemonade3.5
11Iced Tea3.75

Insert several rows at once

Separate each row’s values with a comma. One statement is faster than many single inserts.

INSERT INTO customers (id, name, city, joined)
VALUES (9, 'Ivy', 'Boston', '2024-07-10'),
       (10, 'Jon', 'Austin', '2024-07-11');

Check the result:

SELECT id, name, city
FROM customers
WHERE id >= 8;
Result on the SQL Café sample data (3 rows)
idnamecity
8HanaAustin
9IvyBoston
10JonAustin

Insert from a SELECT

Copy rows from a query instead of typing values. Here, everyone in Engineering becomes a new signup record.

INSERT INTO signups (email, signed_up)
SELECT lower(replace(name, ' ', '.')) || '@acme.test', '2026-01-01'
FROM employees
WHERE department_id = 1;

Check the result:

SELECT email, signed_up
FROM signups
WHERE signed_up = '2026-01-01';
Result on the Acme Co. (company data) sample data (5 rows)
emailsigned_up
[email protected]2026-01-01
[email protected]2026-01-01
[email protected]2026-01-01
[email protected]2026-01-01
[email protected]2026-01-01

Common mistakes

Practice INSERT INTO interactively

Write real queries in your browser and get instant feedback in the lesson “INSERT” (Unit 9). New learners can start free from the first lesson.

Frequently asked questions

How do I get the id of the row I just inserted?

RETURNING id in PostgreSQL and SQLite 3.35+, LAST_INSERT_ID() in MySQL, OUTPUT inserted.id or SCOPE_IDENTITY() in SQL Server.

How do I insert only if the row doesn’t exist?

Use INSERT ... ON CONFLICT DO NOTHING in PostgreSQL and SQLite, or INSERT IGNORE in MySQL.

Related SQL tutorials