SQLite CRUD and SELECT Cheatsheet

High-value SELECT, INSERT, UPDATE, DELETE, UPSERT, ORDER BY, LIMIT, and filtering patterns for day-to-day SQLite development.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Read and filter rows
Select all columns
SELECT * FROM users;

# Read rows from a table.

Select only needed columns
SELECT id, email, created_at FROM users;

# Return a smaller projection.

Filter with WHERE and LIKE
SELECT id, title FROM posts WHERE title LIKE '%sqlite%';

# Find rows by pattern.

Sort and limit results
SELECT id, email, created_at FROM users ORDER BY created_at DESC LIMIT 20;

# Get recent rows first.

Paginate with LIMIT and OFFSET
SELECT id, email FROM users ORDER BY id LIMIT 20 OFFSET 40;

# Fetch one page of rows.

## Insert, update, delete, and upsert
Insert one row
INSERT INTO users (email, display_name) VALUES ('ava@example.com', 'Ava');

# Add a new record.

Insert multiple rows
INSERT INTO tags (name) VALUES ('sql'), ('sqlite'), ('database');

# Add several records in one statement.

Update matching rows
UPDATE users SET timezone = 'America/Los_Angeles' WHERE id = 1;

# Modify one or more records.

Delete matching rows
DELETE FROM sessions WHERE expires_at < CURRENT_TIMESTAMP;

# Remove records by condition.

Upsert with ON CONFLICT
INSERT INTO users (email, display_name)
VALUES ('ava@example.com', 'Ava Martin')
ON CONFLICT(email) DO UPDATE SET display_name = excluded.display_name;

# Insert or update on a uniqueness collision.

Ignore duplicates on conflict
INSERT INTO tags (name) VALUES ('sqlite') ON CONFLICT(name) DO NOTHING;

# Keep the existing row when a unique key collides.

Recommended next

No recommendations yet.